-
Notifications
You must be signed in to change notification settings - Fork 15.3k
Open
Labels
c++clang:diagnosticsNew/improved warning or error message in Clang, but not in clang-tidy or static analyzerNew/improved warning or error message in Clang, but not in clang-tidy or static analyzergood first issuehttps://github.com/llvm/llvm-project/contributehttps://github.com/llvm/llvm-project/contribute
Description
Consider the following example (https://godbolt.org/z/P7dqa81bG):
class S {
class Incomplete;
struct Inner {
consteval void fn() {
Incomplete i;
}
};
static constexpr int r = [] {
Inner{}.fn();
return 0;
}();
class Incomplete {};
};We issue the following diagnostics for it:
<source>:10:28: error: call to immediate function 'S::(anonymous class)::operator()' is not a constant expression
10 | static constexpr int r = [] {
| ^
<source>:11:13: note: undefined function 'fn' cannot be used in a constant expression
11 | Inner{}.fn();
| ^
<source>:10:28: note: in call to '[] {
Inner{}.fn();
return 0;
}.operator()()'
10 | static constexpr int r = [] {
| ^~~~
11 | Inner{}.fn();
| ~~~~~~~~~~~~~
12 | return 0;
| ~~~~~~~~~
13 | }();
| ~~~
<source>:5:20: note: declared here
5 | consteval void fn() {
| ^
<source>:10:24: error: constexpr variable 'r' must be initialized by a constant expression
10 | static constexpr int r = [] {
| ^ ~~~~
11 | Inner{}.fn();
| ~~~~~~~~~~~~~
12 | return 0;
| ~~~~~~~~~
13 | }();
| ~~~
<source>:11:13: note: undefined function 'fn' cannot be used in a constant expression
11 | Inner{}.fn();
| ^
<source>:10:28: note: in call to '[] {
Inner{}.fn();
return 0;
}.operator()()'
10 | static constexpr int r = [] {
| ^~~~
11 | Inner{}.fn();
| ~~~~~~~~~~~~~
12 | return 0;
| ~~~~~~~~~
13 | }();
| ~~~
<source>:5:20: note: declared here
5 | consteval void fn() {
| ^
2 errors generated.
It seems unfortunate that multi-line lambda body gets printed in the in call to note.
frederick-vs-ja
Metadata
Metadata
Assignees
Labels
c++clang:diagnosticsNew/improved warning or error message in Clang, but not in clang-tidy or static analyzerNew/improved warning or error message in Clang, but not in clang-tidy or static analyzergood first issuehttps://github.com/llvm/llvm-project/contributehttps://github.com/llvm/llvm-project/contribute