Commit 57e61764 by Jonathan Wakely Committed by Jonathan Wakely

PR c++/90243 - orphaned note in uninstantiated constexpr function

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
parent 700e6332
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> 2019-04-26 Paolo Carlini <paolo.carlini@oracle.com>
PR c++/90173 PR c++/90173
......
...@@ -5691,13 +5691,15 @@ check_for_uninitialized_const_var (tree decl, bool constexpr_context_p, ...@@ -5691,13 +5691,15 @@ check_for_uninitialized_const_var (tree decl, bool constexpr_context_p,
if (!field) if (!field)
return true; return true;
bool show_notes = true;
if (!constexpr_context_p) if (!constexpr_context_p)
{ {
if (CP_TYPE_CONST_P (type)) if (CP_TYPE_CONST_P (type))
{ {
if (complain & tf_error) if (complain & tf_error)
permerror (DECL_SOURCE_LOCATION (decl), show_notes = permerror (DECL_SOURCE_LOCATION (decl),
"uninitialized const %qD", decl); "uninitialized const %qD", decl);
} }
else else
{ {
...@@ -5706,6 +5708,8 @@ check_for_uninitialized_const_var (tree decl, bool constexpr_context_p, ...@@ -5706,6 +5708,8 @@ check_for_uninitialized_const_var (tree decl, bool constexpr_context_p,
error_at (DECL_SOURCE_LOCATION (decl), error_at (DECL_SOURCE_LOCATION (decl),
"uninitialized variable %qD in %<constexpr%> " "uninitialized variable %qD in %<constexpr%> "
"function", decl); "function", decl);
else
show_notes = false;
cp_function_chain->invalid_constexpr = true; cp_function_chain->invalid_constexpr = true;
} }
} }
...@@ -5714,7 +5718,7 @@ check_for_uninitialized_const_var (tree decl, bool constexpr_context_p, ...@@ -5714,7 +5718,7 @@ check_for_uninitialized_const_var (tree decl, bool constexpr_context_p,
"uninitialized variable %qD in %<constexpr%> context", "uninitialized variable %qD in %<constexpr%> context",
decl); decl);
if (CLASS_TYPE_P (type) && (complain & tf_error)) if (show_notes && CLASS_TYPE_P (type) && (complain & tf_error))
{ {
tree defaulted_ctor; tree defaulted_ctor;
......
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> 2019-04-26 Paolo Carlini <paolo.carlini@oracle.com>
PR c++/90173 PR c++/90173
......
// { 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); }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment