Skip to content

[Clang] consteval functions called in NSDMI during aggregate initialization rejected if they use this #104908

@MitalAshok

Description

@MitalAshok

Similar to https://eel.is/c++draft/expr.const#example-9

https://godbolt.org/z/zY3x1foG7

consteval int id(int i) { return i; }

struct A {
  int x;
  int y = id(x);
} a{42};

Clang rejects this:

<source>:5:11: error: call to consteval function 'id' is not a constant expression
    5 |   int y = id(x);
      |           ^
<source>:6:7: note: in the default initializer of 'y'
    6 | } a{42};
      |       ^
<source>:5:3: note: declared here
    5 |   int y = id(x);
      |   ^
<source>:5:14: note: implicit use of 'this' pointer is only allowed within the evaluation of a call to a 'constexpr' member function
    5 |   int y = id(x);
      |              ^

MSVC also rejects this but GCC does not.

Clang does accept a{ 42, id(a.x) }

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