<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/94746>94746</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Error diagnostic is expected for the constexpr
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang:diagnostics
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
romanova-ekaterina
</td>
</tr>
</table>
<pre>
I'm going through some C++ standard compliance related tests where a diagnostic is supposed to be reported (but not reported by clang compiler).
It seems that the error should be reported for this lineĀ
constexpr int max = maximum( 2, 5 ); // Does error need to be reported here?
but I'm not 100% convinced. The testcase is below. It will be nice to hear a final verdict from a C++ standard expert.
https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4296.pdf
C++14 Standard (ISO/IEC 14882:2014), Section 5.20, Paragraph 2 says:
(2) A conditional-expression e is a core constant expression unless the evaluation of e, following the rules of the abstract machine (1.9), would evaluate one of the following expressions:
...
(2.7) an lvalue-to-rvalue conversion (4.1) unless it is applied to
....
(2.7.3) a non-volatile glvalue that refers to a non-volatile object defined with constexpr, or that refers to a non-mutable sub-object of such an object
Consider the following test case:
```
template <class T> class Test_Class {
public:
mutable T value;
constexpr void fmax( T a1, T a2 ) const { value = a1 > a2 ? a1 : a2; }
constexpr Test_Class() : value(0) {}
};
constexpr int maximum( int a1, int a2 ){
const Test_Class<int> foo;
foo.fmax( a1, a2 );
return foo.value;
}
int main(){
constexpr int max = maximum( 2, 5 ); // Does error need to be reported here?
// See C++14 Standard (ISO/IEC 14882:2014), Section 5.20, Paragraph 2.
return max;
}
```
Note: GCC (version 10.2.0) reports an error.
```
test.cpp: In function 'int main()':
test.cpp:16:32: in 'constexpr' expansion of 'maximum(2, 5)'
test.cpp:16:39: error: mutable 'Test_Class<int>::value' is not usable in a constant expression
16 | constexpr int max = maximum( 2, 5 ); // Does error need to be reported here?
| ^
```
Clang doesn't report an error.
</pre>
<img width="1px" height="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