https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118249
Bug ID: 118249 Summary: Misdiagnosing use of 'this' while doing class member access in constant evaluation Product: gcc Version: 14.1.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: barry.revzin at gmail dot com Target Milestone: --- Short example: template <int I> void f() { } template <int N> struct array { constexpr int size() const { return N; } }; array<10> outer; struct C { array<10> inner; void g() { f<outer.size()>(); // #1 f<inner.size()>(); // #2 } }; Both calls to f should be okay since P2280 (unknown references in constant expressions). gcc allows #1, but rejects #2 due to: <source>:16:22: error: use of 'this' in a constant expression 16 | f<inner.size()>(); // #2 | ^ But the same paper that allowed #1 also extended the rule for using `this` to allow its use in class member access expressions, like this one. So #2 should be okay too.