<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 - contexpr return type from a member function is allowed where it should not"
href="https://bugs.llvm.org/show_bug.cgi?id=32904">32904</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>contexpr return type from a member function is allowed where it should not
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>4.0
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>Linux
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>normal
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>C++14
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>mikhail.katliar@tuebingen.mpg.de
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org
</td>
</tr></table>
<p>
<div>
<pre>Minimal example:
#include <iostream>
int f()
{
static int n = 42;
return n++;
}
struct A
{
A()
: f_(&f)
{
}
int constexpr n() const
{
return f_();
}
int (*f_)();
};
int main(int, char **)
{
std::cout << A().n() << std::endl;
std::cout << A().n() << std::endl;
return 0;
}
Build with clang:
$ clang++ -std=c++14 example.cpp
Run:
$ ./a.out
42
43
Try building with gcc:
$ g++ -std=c++14 example.cpp
example.cpp:17:19: error: enclosing class of constexpr non-static member
function ‘int A::n() const’ is not a literal type
int constexpr n() const
^
example.cpp:9:8: note: ‘A’ is not literal because:
struct A
^
example.cpp:9:8: note: ‘A’ is not an aggregate, does not have a trivial
default constructor, and has no constexpr constructor that is not a copy or
move constructor</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>