[llvm-bugs] [Bug 32904] New: contexpr return type from a member function is allowed where it should not
via llvm-bugs
llvm-bugs at lists.llvm.org
Wed May 3 03:21:42 PDT 2017
https://bugs.llvm.org/show_bug.cgi?id=32904
Bug ID: 32904
Summary: contexpr return type from a member function is allowed
where it should not
Product: clang
Version: 4.0
Hardware: PC
OS: Linux
Status: NEW
Severity: normal
Priority: P
Component: C++14
Assignee: unassignedclangbugs at nondot.org
Reporter: mikhail.katliar at tuebingen.mpg.de
CC: llvm-bugs at lists.llvm.org
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
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20170503/943689f5/attachment.html>
More information about the llvm-bugs
mailing list