We mention 'X::__ct' instead of 'X::X' in the "names the constructor,
not the type" error for this invalid code:
=== cut here ===
struct X {};
void g () {
X::X x;
}
=== cut here ===
The problem is that we use %<%T::%D%> to build the error message, while
%qE does exactly what we need since we have DECL_CONSTRUCTOR_P. This is
what this patch does, along with skipping until the end of the statement
to avoid emitting extra (useless) errors.
Successfully tested on x86_64-pc-linux-gnu.
PR c++/105483
gcc/cp/ChangeLog:
* parser.cc (cp_parser_expression_statement): Use %qE instead of
incorrect %<%T::%D%>, and skip to end of statement.
gcc/testsuite/ChangeLog:
* g++.dg/tc1/dr147.C: Adjust test expectation.
* g++.dg/diagnostic/pr105483.C: New test.
---
gcc/cp/parser.cc | 7 ++++---
gcc/testsuite/g++.dg/diagnostic/pr105483.C | 7 +++++++
gcc/testsuite/g++.dg/tc1/dr147.C | 2 +-
3 files changed, 12 insertions(+), 4 deletions(-)
create mode 100644 gcc/testsuite/g++.dg/diagnostic/pr105483.C
diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc
index 28ebf2beb60..ef4e3838a86 100644
--- a/gcc/cp/parser.cc
+++ b/gcc/cp/parser.cc
@@ -13240,10 +13240,11 @@ cp_parser_expression_statement (cp_parser* parser,
tree in_statement_expr)
&& DECL_CONSTRUCTOR_P (get_first_fn (statement)))
{
/* A::A a; */
- tree fn = get_first_fn (statement);
error_at (token->location,
- "%<%T::%D%> names the constructor, not the type",
- DECL_CONTEXT (fn), DECL_NAME (fn));
+ "%qE names the constructor, not the type",
+ get_first_fn (statement));
+ cp_parser_skip_to_end_of_block_or_statement (parser);
+ return error_mark_node;
}
}
diff --git a/gcc/testsuite/g++.dg/diagnostic/pr105483.C
b/gcc/testsuite/g++.dg/diagnostic/pr105483.C
new file mode 100644
index 00000000000..b935bacea11
--- /dev/null
+++ b/gcc/testsuite/g++.dg/diagnostic/pr105483.C
@@ -0,0 +1,7 @@
+// PR c++/105483
+// { dg-do compile }
+
+struct X { };
+void g () {
+ X::X x; // { dg-error "'X::X' names the constructor" }
+}
diff --git a/gcc/testsuite/g++.dg/tc1/dr147.C b/gcc/testsuite/g++.dg/tc1/dr147.C
index 6b656491e81..ced18d1879c 100644
--- a/gcc/testsuite/g++.dg/tc1/dr147.C
+++ b/gcc/testsuite/g++.dg/tc1/dr147.C
@@ -21,7 +21,7 @@ void A::f()
void f()
{
A::A a; // { dg-error "constructor" "constructor" }
-} // { dg-error "" "error cascade" { target *-*-* } .-1 } error cascade
+}
}
namespace N2 {
--
2.44.0