Skip to content

Clang rejects valid program involving member access operator with incomplete type CWG 1836 #83424

Open
@ranaanoop

Description

@ranaanoop

The following valid program as explained here is rejected by clang and msvc. Demo

struct TestClass {
  void testFinction() {}
  static TestClass* ptr_;
  constexpr static auto funcPtr = +[](){ ptr_->testFinction(); };
};

TestClass* TestClass::ptr_ = new TestClass();

int main() {
  TestClass::funcPtr();
  delete TestClass::ptr_;
  return 0;
}

Clang says:

<source>:4:46: error: member access into incomplete type 'TestClass'
    4 |   constexpr static auto funcPtr = +[](){ ptr_->testFinction(); };
      |                                              ^
<source>:1:8: note: definition of 'TestClass' is not complete until the closing '}'
    1 | struct TestClass {
      |        ^
1 error generated.
Compiler returned: 1

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:frontendLanguage frontend issues, e.g. anything involving "Sema"confirmedVerified by a second partyrejects-valid

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions