PR c++/90243 - orphaned note in uninstantiated constexpr function
authorJonathan Wakely <jwakely@redhat.com>
Fri, 26 Apr 2019 16:33:02 +0000 (17:33 +0100)
committerJonathan Wakely <redi@gcc.gnu.org>
Fri, 26 Apr 2019 16:33:02 +0000 (17:33 +0100)
gcc/cp:

PR c++/90243 - orphaned note in uninstantiated constexpr function
* decl.c (check_for_uninitialized_const_var): Suppress notes if no
error was shown.

gcc/testsuite:

PR c++/90243
* g++.dg/diagnostic/pr90243.C: New test.

From-SVN: r270610

gcc/cp/ChangeLog
gcc/cp/decl.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/diagnostic/pr90243.C [new file with mode: 0644]

index ab25cb94d3d6dcc84256627c15f6362d8444cf1b..e0a7fb9d5beb703073f4a267efbf7988b6ef4405 100644 (file)
@@ -1,3 +1,9 @@
+2019-04-26  Jonathan Wakely  <jwakely@redhat.com>
+
+       PR c++/90243 - orphaned note in uninstantiated constexpr function
+       * decl.c (check_for_uninitialized_const_var): Suppress notes if no
+       error was shown.
+
 2019-04-26  Paolo Carlini  <paolo.carlini@oracle.com>
 
        PR c++/90173
index ca21cbb9917d04b4609bb3900afb2cff6922558e..20a6e2e5b5c19afa36b152923e9c215c3bc5fac3 100644 (file)
@@ -5691,13 +5691,15 @@ check_for_uninitialized_const_var (tree decl, bool constexpr_context_p,
       if (!field)
        return true;
 
+      bool show_notes = true;
+
       if (!constexpr_context_p)
        {
          if (CP_TYPE_CONST_P (type))
            {
              if (complain & tf_error)
-               permerror (DECL_SOURCE_LOCATION (decl),
-                          "uninitialized const %qD", decl);
+               show_notes = permerror (DECL_SOURCE_LOCATION (decl),
+                                       "uninitialized const %qD", decl);
            }
          else
            {
@@ -5706,6 +5708,8 @@ check_for_uninitialized_const_var (tree decl, bool constexpr_context_p,
                error_at (DECL_SOURCE_LOCATION (decl),
                          "uninitialized variable %qD in %<constexpr%> "
                          "function", decl);
+             else
+               show_notes = false;
              cp_function_chain->invalid_constexpr = true;
            }
        }
@@ -5714,7 +5718,7 @@ check_for_uninitialized_const_var (tree decl, bool constexpr_context_p,
                  "uninitialized variable %qD in %<constexpr%> context",
                  decl);
 
-      if (CLASS_TYPE_P (type) && (complain & tf_error))
+      if (show_notes && CLASS_TYPE_P (type) && (complain & tf_error))
        {
          tree defaulted_ctor;
 
index 2ada8268029460be3485448852894f920a420c33..9322205f0f51a33292e5c91380c2894a91f3c487 100644 (file)
@@ -1,3 +1,8 @@
+2019-04-26  Jonathan Wakely  <jwakely@redhat.com>
+
+       PR c++/90243
+       * g++.dg/diagnostic/pr90243.C: New test.
+
 2019-04-26  Paolo Carlini  <paolo.carlini@oracle.com>
 
        PR c++/90173
diff --git a/gcc/testsuite/g++.dg/diagnostic/pr90243.C b/gcc/testsuite/g++.dg/diagnostic/pr90243.C
new file mode 100644 (file)
index 0000000..3f5d915
--- /dev/null
@@ -0,0 +1,13 @@
+// { dg-do compile { target c++14 } }
+struct Z { // { dg-bogus "default constructor" }
+  int y;   // { dg-bogus "initialize" }
+};
+
+template <class T>
+constexpr Z f(const T *data) {
+  Z z;
+  __builtin_memcpy(&z, data, sizeof(z));
+  return z;
+}
+
+constexpr Z g(const char *data) { return f(data); }