Here are two small constexpr changes that I made while working on C++14 constexpr support that I thought should go in separately. The first clarifies the error about missing mem-initializers in constexpr constructors so that people aren't confused about why assigning to the field in the constructor body doesn't count as initialization.

The second is a small optimization opportunity that I noticed.

Tested x86_64-pc-linux-gnu, applying to trunk.

commit 2b9db1c0982dfdee378b41039a37262d87575e25
Author: Jason Merrill <ja...@redhat.com>
Date:   Thu Nov 13 20:44:02 2014 -0500

    	* constexpr.c (cx_check_missing_mem_inits): Clarify error message.

diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c
index d30bf635..0d45f31 100644
--- a/gcc/cp/constexpr.c
+++ b/gcc/cp/constexpr.c
@@ -716,8 +716,9 @@ cx_check_missing_mem_inits (tree fun, tree body, bool complain)
 	    }
 	  if (!complain)
 	    return true;
-	  error ("uninitialized member %qD in %<constexpr%> constructor",
-		 field);
+	  error ("member %qD must be initialized by mem-initializer "
+		 "in %<constexpr%> constructor", field);
+	  inform (DECL_SOURCE_LOCATION (field), "declared here");
 	  bad = true;
 	}
       if (field == NULL_TREE)
diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-ctor.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-ctor.C
index 659e733..55beda7 100644
--- a/gcc/testsuite/g++.dg/cpp0x/constexpr-ctor.C
+++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-ctor.C
@@ -3,5 +3,5 @@
 struct A
 {
   int i;
-  constexpr A() { }		// { dg-error "uninitialized member .A::i" }
+  constexpr A() { }		// { dg-error "A::i" }
 };
diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-diag4.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-diag4.C
index 29f574d..13ca6fa 100644
--- a/gcc/testsuite/g++.dg/cpp0x/constexpr-diag4.C
+++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-diag4.C
@@ -21,5 +21,5 @@ struct A1
 struct B1
 {
     A1 a1;
-    constexpr B1() {} // { dg-error "uninitialized member" }
+    constexpr B1() {} // { dg-error "B1::a1" }
 };
diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-ex3.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-ex3.C
index 3e2685b..a589356 100644
--- a/gcc/testsuite/g++.dg/cpp0x/constexpr-ex3.C
+++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-ex3.C
@@ -6,7 +6,7 @@
 struct A
 {
   int i;
-  constexpr A(int _i) { i = _i; } // { dg-error "empty body|uninitialized member" }
+  constexpr A(int _i) { i = _i; } // { dg-error "empty body|A::i" }
 };
 
 template <class T>
diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-template2.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-template2.C
index a316b34..12a8d42 100644
--- a/gcc/testsuite/g++.dg/cpp0x/constexpr-template2.C
+++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-template2.C
@@ -3,7 +3,7 @@
 template <class T> struct A
 {
   T t;
-  constexpr A() { }		// { dg-error "uninitialized" }
+  constexpr A() { }		// { dg-error "::t" }
 };
 
 int main()
diff --git a/gcc/testsuite/g++.dg/cpp0x/nsdmi3.C b/gcc/testsuite/g++.dg/cpp0x/nsdmi3.C
index 6ac414b..d2e7439 100644
--- a/gcc/testsuite/g++.dg/cpp0x/nsdmi3.C
+++ b/gcc/testsuite/g++.dg/cpp0x/nsdmi3.C
@@ -15,4 +15,4 @@ struct B
 
 constexpr B b;			// { dg-error "B::B" }
 
-// { dg-prune-output "uninitialized member" }
+// { dg-prune-output "B::a1" }
commit ac8ad66594ec8fcf2c3a1a03b71f0f3b4e6825e5
Author: Jason Merrill <ja...@redhat.com>
Date:   Sat Nov 15 00:53:13 2014 -0500

    	* constexpr.c (cxx_eval_builtin_function_call): Use
    	fold_builtin_call_array.

diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c
index 0d45f31..66d356f 100644
--- a/gcc/cp/constexpr.c
+++ b/gcc/cp/constexpr.c
@@ -995,9 +995,8 @@ cxx_eval_builtin_function_call (const constexpr_ctx *ctx, tree t,
     }
   if (*non_constant_p)
     return t;
-  new_call = build_call_array_loc (EXPR_LOCATION (t), TREE_TYPE (t),
-                                   CALL_EXPR_FN (t), nargs, args);
-  new_call = fold (new_call);
+  new_call = fold_builtin_call_array (EXPR_LOCATION (t), TREE_TYPE (t),
+				      CALL_EXPR_FN (t), nargs, args);
   VERIFY_CONSTANT (new_call);
   return new_call;
 }

Reply via email to