<html>
<head>
<base href="https://bugs.llvm.org/">
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW - case value is not a constant expression with c++11 and beyond"
href="https://bugs.llvm.org/show_bug.cgi?id=38472">38472</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>case value is not a constant expression with c++11 and beyond
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>trunk
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>Windows NT
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>enhancement
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>Driver
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>steveire@gmail.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org
</td>
</tr></table>
<p>
<div>
<pre>This code extracted from real code causes clang diagnostics to be issued from
clang-tidy, and from clang++.exe in c++11 mode, but not from clang-cl.exe and
not from clang++.exe in c++98 mode:
template<typename ENUM>
class MyEnum
{
public:
MyEnum()
{
}
MyEnum(ENUM)
{
}
operator ENUM() const { return static_cast<ENUM>(0); }
};
enum Enum
{
SomeValue
};
#ifdef BROKEN
template<typename T>
#endif
struct Templ
{
Templ()
{
switch (m_enumMember)
#if 0
switch (static_cast<Enum>(m_enumMember))
#endif
{
case SomeValue:
break;
}
}
MyEnum<Enum> m_enumMember;
};
int main()
{
#ifdef BROKEN
Templ<int> t1;
#else
Templ t2;
#endif
}
The error only occurs if Templ is a template and instantiated.
C:\dev\src\llvm\build\releaseprefix\bin\clang++.exe -Weverything -std=c++11 -c
-DBROKEN diagerror.cpp
diagerror.cpp
diagerror.cpp:29:14: error: case value is not a constant expression
case SomeValue:
^~~~~~~~~
diagerror.cpp:29:14: note: non-constexpr constructor 'MyEnum' cannot be used in
a constant expression
diagerror.cpp:9:5: note: declared here
MyEnum(ENUM)
^
diagerror.cpp:27:17: warning: enumeration value 'SomeValue' not handled in
switch [-Wswitch]
switch (m_enumMember)
^
1 warning and 1 error generated.
I don't understand why the error only occurs when used in a template.
It would be good if there were some way to trigger the error with clang-cl.</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>