Issue 58080
Summary Confusing "undefined constructor cannot be used in a constant _expression_" error in nested class
Labels clang:diagnostics
Assignees
Reporter zmodem
    Consider (https://godbolt.org/z/M4sPT137a):

```
$ cat /tmp/a.cc
struct S {
    static constexpr struct T {
        constexpr T() {}
    } t = {};
};
$ clang -c /tmp/a.cc
/tmp/a.cc:4:7: error: constexpr variable 't' must be initialized by a constant _expression_
    } t = {};
      ^   ~~
/tmp/a.cc:4:11: note: undefined constructor 'T' cannot be used in a constant _expression_
    } t = {};
          ^
/tmp/a.cc:3:19: note: declared here
        constexpr T() {}
                  ^
1 error generated.
```

This is confusing: the definition of the constructor is right there on line 3, clang is even pointing it out in the note.

I suppose it's considered undefined for some technical reason, and perhaps clang could explain it?

GCC is more terse but does include a hint:

```
error: 'constexpr S::T::T()' called in a constant _expression_ before its definition is complete
```

Aha, maybe it won't be complete until the end of the outermost class definition? It would be cool if the compiler could say so.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to