aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Merrill <jason@redhat.com>2015-01-21 15:15:35 -0500
committerJason Merrill <jason@gcc.gnu.org>2015-01-21 15:15:35 -0500
commitf1eac182405b9540c9ddecc9d72459fe82aa3f61 (patch)
treefdd7f4713bdc6f43894c0056c5ed80b763e82ab5
parent6875457f349eebb3d13d780e909b131bfff87e16 (diff)
downloadgcc-f1eac182405b9540c9ddecc9d72459fe82aa3f61.zip
gcc-f1eac182405b9540c9ddecc9d72459fe82aa3f61.tar.gz
gcc-f1eac182405b9540c9ddecc9d72459fe82aa3f61.tar.bz2
re PR c++/64647 ([C++14] std::__max_element contains code not allowed in constexpr function)
PR c++/64647 * constexpr.c (ensure_literal_type_for_constexpr_object): Don't give a hard error in a template instantiation. From-SVN: r219965
-rw-r--r--gcc/cp/ChangeLog6
-rw-r--r--gcc/cp/constexpr.c16
-rw-r--r--gcc/testsuite/g++.dg/cpp1y/constexpr-local3.C20
3 files changed, 37 insertions, 5 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index d5b3cd8..526742c 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,9 @@
+2015-01-21 Jason Merrill <jason@redhat.com>
+
+ PR c++/64647
+ * constexpr.c (ensure_literal_type_for_constexpr_object): Don't
+ give a hard error in a template instantiation.
+
2015-01-21 Richard Biener <rguenther@suse.de>
PR middle-end/64313
diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c
index 0d47424..decc84d 100644
--- a/gcc/cp/constexpr.c
+++ b/gcc/cp/constexpr.c
@@ -102,15 +102,21 @@ ensure_literal_type_for_constexpr_object (tree decl)
else if (!literal_type_p (type))
{
if (DECL_DECLARED_CONSTEXPR_P (decl))
- error ("the type %qT of constexpr variable %qD is not literal",
- type, decl);
+ {
+ error ("the type %qT of constexpr variable %qD is not literal",
+ type, decl);
+ explain_non_literal_class (type);
+ }
else
{
- error ("variable %qD of non-literal type %qT in %<constexpr%> "
- "function", decl, type);
+ if (!DECL_TEMPLATE_INSTANTIATION (current_function_decl))
+ {
+ error ("variable %qD of non-literal type %qT in %<constexpr%> "
+ "function", decl, type);
+ explain_non_literal_class (type);
+ }
cp_function_chain->invalid_constexpr = true;
}
- explain_non_literal_class (type);
return NULL;
}
}
diff --git a/gcc/testsuite/g++.dg/cpp1y/constexpr-local3.C b/gcc/testsuite/g++.dg/cpp1y/constexpr-local3.C
new file mode 100644
index 0000000..76d4b55
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp1y/constexpr-local3.C
@@ -0,0 +1,20 @@
+// PR c++/64647
+// { dg-do compile { target c++14 } }
+
+template<typename T>
+constexpr T foo(T t)
+{
+ T tt = t;
+ return tt;
+}
+
+struct X
+{
+ X() { }
+};
+
+int main()
+{
+ X x;
+ foo(x);
+}