Issue |
156255
|
Summary |
[clang] Incorrect constexpr member function definition order dependency
|
Labels |
clang
|
Assignees |
|
Reporter |
pdimov
|
The following code
```
class X
{
public:
constexpr int f( int x ) const
{
return g( x );
}
private:
template<class T>
constexpr T g( T x ) const
{
return x;
}
};
constexpr int x = X().f( 1 );
```
is [rejected](https://godbolt.org/z/ox1E8nG7M) by Clang trunk (and all previous versions AFAICS) with
```
<source>:7:16: note: undefined function 'g<int>' cannot be used in a constant _expression_
7 | return g( x );
| ^
```
and in order to fix that, the definition of `g` needs to be moved above that of `f`.
But I don't think this order dependency is required by the standard, and [other](https://godbolt.org/z/qMe1dPMTM) [compilers](https://godbolt.org/z/dnrz95orn) accept the code.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs