Skip to content

Clang rejects valid program involving calling of a member function of an incomplete type inside class definitionΒ #110359

@ranaanoop

Description

@ranaanoop

The following valid program is rejected by clang and msvc but accepted by gcc. Demo

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

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

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

Clang says:

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

expr.post#expr.ref and CWG 1836 makes this well-formed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:frontendLanguage frontend issues, e.g. anything involving "Sema"diverges-from:gccDoes the clang frontend diverge from gcc on this issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions