[LLVMbugs] [Bug 18874] New: constexpr function ill-formed but error message incorrect
bugzilla-daemon at llvm.org
bugzilla-daemon at llvm.org
Mon Feb 17 10:47:17 PST 2014
http://llvm.org/bugs/show_bug.cgi?id=18874
Bug ID: 18874
Summary: constexpr function ill-formed but error message
incorrect
Product: clang
Version: trunk
Hardware: Other
OS: other
Status: NEW
Severity: normal
Priority: P
Component: C++1y
Assignee: unassignedclangbugs at nondot.org
Reporter: yaghmour.shafik at gmail.com
CC: llvmbugs at cs.uiuc.edu
Classification: Unclassified
In the following program:
#include <cstddef>
template <typename T, size_t s>
struct test
{
T x[s] ;
} ;
template <typename T>
constexpr T func() {
test<T,3> test1 ;
test1.x[0] = 10 ;
return test1.x[0];
}
constexpr int func2() {
test<int,3> test1 ;
test1.x[0] = 10 ;
return test1.x[0];
}
int main()
{
constexpr int x = func<int>();
}
func and func2 should be ill-formed for the same reason that variable test1 is
not initialized nor does it have a constexpr constructor but in func the error
message is:
main.cpp:13:11: note: assignment to object outside its lifetime is not
allowed in a constant expression
test1.x[0] = 10 ;
^
which does not make any sense since test1 should be trivial and it's lifetime
should begin with it's declaration and extend over the whole function.
I would expect an error similar to the one we see for func2 which is as
follows:
main.cpp:20:14: note: non-constexpr constructor 'test' cannot be used in a
constant expression
test<int,3> test1 ;
^
I am building using the following command line:
clang++ -std=c++1y -O0 -Wall -Wextra -Wconversion -pedantic
You can see this on Coliru here:
http://coliru.stacked-crooked.com/a/16ed43ed478fbc55
This was originally brought up in this StackOverflow question:
http://stackoverflow.com/questions/21806154/c1y-c14-assignment-to-object-outside-its-lifetime-is-not-allowed-in-a-const
This does not seem like a major bug but the error message sure is confusing.
--
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/20140217/a91685de/attachment.html>
More information about the llvm-bugs
mailing list