Commit 4bb8ca28 by Mark Mitchell Committed by Mark Mitchell

re PR c++/10779 (Error cascade for unknown type in function prototype)

	* c-common.h (c_parse_error): Declare it.
	* c-common.c (c_parse_error): New function.
	* c-parse.y (yyerror): Use it.

	* parser.c (struct cp_parser): Add in_template_argument_list_p.
	(cp_parser_error): Use c_parse_error.
	(cp_parser_name_lookup_error): New function.
	(cp_parser_new): Initialize it.
	(cp_parser_declarator): Add parenthesized_p parameter.
	(cp_parser_nested_name_specifier_opt): Use
	cp_parser_name_lookup_error.
	(cp_parser_parenthesized_expression_list): Improve comments.
	(cp_parser_condition): Adjust call to cp_parser_declarator.
	(cp_parser_template_parameter): Adjust call to
	cp_parser_parameter_declaration.
	(cp_parser_template_argument_list): Set
	in_template_argument_list_p.
	(cp_parser_explicit_instantiation): Adjust call to
	cp_parser_declarator.
	(cp_parser_simple_type_specifier): Remove unncessary code.
	(cp_parser_using_declaration): Use cp_parser_name_lookup_error.
	(cp_parser_init_declarator): Handle member function definitions.
	(cp_parser_direct_declarator): Adjust call to
	cp_parser_declarator.
	(cp_parser_type_id): Adjust call to cp_parser_declarator.
	(cp_parser_parameter_declaration_list): Avoid backtracking where
	possible.
	(cp_parser_parameter_declaration): Add parenthesized_p parameter.
	(cp_parser_function_definition): Remove.
	(cp_parser_member_declaration): Do not backtrack to look for
	function definitions.
	(cp_parser_exception_declaration): Adjust call to
	cp_parser_declarator.
	(cp_parser_single_declaration): Handle function definitions via
	cp_parser_init_declarator.
	(cp_parser_save_member_function_body): New function.

	PR c++/10779
	PR c++/12160
	* g++.dg/parse/error3.C: New test.
	* g++.dg/parse/error4.C: Likewise.
	* g++.dg/abi/mangle4.C: Tweak error messages.
	* g++.dg/lookup/using5.C: Likewise.
	* g++.dg/other/error2.C: Likewise.
	* g++.dg/parse/typename5.C: Likewise.
	* g++.dg/parse/undefined1.C: Likewise.
	* g++.dg/template/arg2.C: Likewise.
	* g++.dg/template/ttp3.C: Likewise.
	* g++.dg/template/type1.C: Likewise.
	* g++.old-deja/g++.other/crash32.C: Likewise.
	* g++.old-djea/g++.pt/defarg8.C: Likewise.

From-SVN: r74624
parent 69f36495
2003-12-14 Mark Mitchell <mark@codesourcery.com>
* c-common.h (c_parse_error): Declare it.
* c-common.c (c_parse_error): New function.
* c-parse.y (yyerror): Use it.
2003-12-14 John David Anglin <dave.anglin@nrc-cnrc.gc.ca>
PR target/13054
......
......@@ -5893,4 +5893,36 @@ c_decl_uninit (tree t)
return false;
}
/* Issue the error given by MSGID, indicating that it occurred before
TOKEN, which had the associated VALUE. */
void
c_parse_error (const char *msgid, enum cpp_ttype token, tree value)
{
const char *string = _(msgid);
if (token == CPP_EOF)
error ("%s at end of input", string);
else if (token == CPP_CHAR || token == CPP_WCHAR)
{
unsigned int val = TREE_INT_CST_LOW (value);
const char *const ell = (token == CPP_CHAR) ? "" : "L";
if (val <= UCHAR_MAX && ISGRAPH (val))
error ("%s before %s'%c'", string, ell, val);
else
error ("%s before %s'\\x%x'", string, ell, val);
}
else if (token == CPP_STRING
|| token == CPP_WSTRING)
error ("%s before string constant", string);
else if (token == CPP_NUMBER)
error ("%s before numeric constant", string);
else if (token == CPP_NAME)
error ("%s before \"%s\"", string, IDENTIFIER_POINTER (value));
else if (token < N_TTYPES)
error ("%s before '%s' token", string, cpp_type2name (token));
else
error ("%s", string);
}
#include "gt-c-common.h"
......@@ -1330,6 +1330,7 @@ extern void c_stddef_cpp_builtins (void);
extern void fe_file_change (const struct line_map *);
extern int c_estimate_num_insns (tree decl);
extern bool c_decl_uninit (tree t);
extern void c_parse_error (const char *, enum cpp_ttype, tree);
/* The following have been moved here from c-tree.h, since they're needed
in the ObjC++ world, too. What is more, stub-objc.c could use a few
......
......@@ -3551,28 +3551,7 @@ init_reswords (void)
static void
yyerror (const char *msgid)
{
const char *string = _(msgid);
if (last_token == CPP_EOF)
error ("%s at end of input", string);
else if (last_token == CPP_CHAR || last_token == CPP_WCHAR)
{
unsigned int val = TREE_INT_CST_LOW (yylval.ttype);
const char *const ell = (last_token == CPP_CHAR) ? "" : "L";
if (val <= UCHAR_MAX && ISGRAPH (val))
error ("%s before %s'%c'", string, ell, val);
else
error ("%s before %s'\\x%x'", string, ell, val);
}
else if (last_token == CPP_STRING
|| last_token == CPP_WSTRING)
error ("%s before string constant", string);
else if (last_token == CPP_NUMBER)
error ("%s before numeric constant", string);
else if (last_token == CPP_NAME)
error ("%s before \"%s\"", string, IDENTIFIER_POINTER (yylval.ttype));
else
error ("%s before '%s' token", string, NAME(last_token));
c_parse_error (msgid, last_token, yylval.ttype);
}
static int
......
2003-12-14 Mark Mitchell <mark@codesourcery.com>
PR c++/10779
PR c++/12160
* parser.c (struct cp_parser): Add in_template_argument_list_p.
(cp_parser_error): Use c_parse_error.
(cp_parser_name_lookup_error): New function.
(cp_parser_new): Initialize it.
(cp_parser_declarator): Add parenthesized_p parameter.
(cp_parser_nested_name_specifier_opt): Use
cp_parser_name_lookup_error.
(cp_parser_parenthesized_expression_list): Improve comments.
(cp_parser_condition): Adjust call to cp_parser_declarator.
(cp_parser_template_parameter): Adjust call to
cp_parser_parameter_declaration.
(cp_parser_template_argument_list): Set
in_template_argument_list_p.
(cp_parser_explicit_instantiation): Adjust call to
cp_parser_declarator.
(cp_parser_simple_type_specifier): Remove unncessary code.
(cp_parser_using_declaration): Use cp_parser_name_lookup_error.
(cp_parser_init_declarator): Handle member function definitions.
(cp_parser_direct_declarator): Adjust call to
cp_parser_declarator.
(cp_parser_type_id): Adjust call to cp_parser_declarator.
(cp_parser_parameter_declaration_list): Avoid backtracking where
possible.
(cp_parser_parameter_declaration): Add parenthesized_p parameter.
(cp_parser_function_definition): Remove.
(cp_parser_member_declaration): Do not backtrack to look for
function definitions.
(cp_parser_exception_declaration): Adjust call to
cp_parser_declarator.
(cp_parser_single_declaration): Handle function definitions via
cp_parser_init_declarator.
(cp_parser_save_member_function_body): New function.
2003-12-14 Kriang Lerdsuwanakij <lerdsuwa@users.sourceforge.net>
PR c++/13106
......
2003-12-14 Mark Mitchell <mark@codesourcery.com>
PR c++/10779
PR c++/12160
* g++.dg/parse/error3.C: New test.
* g++.dg/parse/error4.C: Likewise.
* g++.dg/abi/mangle4.C: Tweak error messages.
* g++.dg/lookup/using5.C: Likewise.
* g++.dg/other/error2.C: Likewise.
* g++.dg/parse/typename5.C: Likewise.
* g++.dg/parse/undefined1.C: Likewise.
* g++.dg/template/arg2.C: Likewise.
* g++.dg/template/ttp3.C: Likewise.
* g++.dg/template/type1.C: Likewise.
* g++.old-deja/g++.other/crash32.C: Likewise.
* g++.old-djea/g++.pt/defarg8.C: Likewise.
2003-12-14 Kriang Lerdsuwanakij <lerdsuwa@users.sourceforge.net>
PR c++/13106
......
......@@ -18,7 +18,7 @@ int main()
C<static_cast<const A*>(&b)> c; // { dg-error "" }
D<&b> d;
E<const_cast<B*>(&b)> e; // { dg-error "" }
f(d, c); // { dg-error "" }
g(d, e); // { dg-error "" }
f(d, c);
g(d, e);
}
......@@ -13,5 +13,5 @@ template <typename> struct A
template <typename T> struct B : A<T>
{
using X::foo; // { dg-error "not a class-name|nested-name-specifier|non-member" }
using X::foo; // { dg-error "declared|nested-name-specifier|non-member" }
};
......@@ -10,5 +10,5 @@ namespace N
class B { friend void operator>>(int, class B); };
class N { friend void operator>>(int,class N); };
}
void N::operator>>(int, N::B) // { dg-error "`B' is not a member of|non-function|primary-expression" "" }
void N::operator>>(int, N::B) // { dg-error "N::N::B" }
{ } // { dg-error "" "" }
// PR c++/10779
static void InstantiateConstraint(const float&, unsigned,
void(*AddFunction)(const TYPE&,bool&, // { dg-error "" }
char*, char*,
unsigned*));
// PR c++/12160
struct X {
virtual void f(int,
itn, // { dg-error "declared" }
int); // { dg-error "" }
};
......@@ -8,5 +8,5 @@ template <typename> struct A {};
template <typename> struct B
{
typedef A<typename X::Y> C; // { dg-error "not a class-name|invalid|no type" }
typedef A<typename X::Y> C; // { dg-error "declared|invalid|no type" }
};
......@@ -7,4 +7,4 @@ struct foo
foo(X) {} // { dg-error "" }
foo(X y, int) : x() {} // { dg-error "" }
}; // { dg-error "" }
};
......@@ -10,5 +10,5 @@ template <typename T> class X {};
void fn ()
{
class L {};
X<L> f; // { dg-error "uses local type|trying to instantiate|expected" "" }
X<L> f; // { dg-error "uses local type|trying to instantiate|no type" "" }
}
......@@ -23,4 +23,4 @@ class List { };
// This next line should just do a lookup of 'class List', and then
// get a type/value mismatch. Instead we try and push 'class List'
// into the global namespace and get a redeclaration error.
vector<class List > data; // { dg-error "invalid|required|expected" "" }
vector<class List > data; // { dg-error "invalid|required|declaration" "" }
......@@ -5,4 +5,4 @@ struct A {
};
int A::B::c; // { dg-error "parameters" }
int A::C::d; // { dg-error "class" }
int A::C::d; // { dg-error "declared" }
......@@ -6,7 +6,7 @@ struct foo
enum e
{
not // { dg-error "" }
}; // { dg-bogus "" "" { xfail *-*-* } }
}; // { dg-bogus "" }
~foo(); // { dg-bogus "" "" { xfail *-*-* } }
void x (foo *&a, bool b = (unsigned char)0);
}; // { dg-bogus "" "" { xfail *-*-* } }
......
......@@ -7,11 +7,11 @@
// so)
template <class T> class foo1;
template <class T, class U> class foo2;
template <class T, class U> class foo2; // { dg-error "" }
struct bar {
template <class T, class U>
bar(int i = foo1<T>::baz, // { dg-bogus "" "" { xfail *-*-* } } -
bar(int i = foo1<T>::baz, // { dg-bogus "" } -
int j = int(foo2<T, U>::baz), // ok
int k = foo2<T, U>::baz) {} // this is the problematic one.
int k = foo2<T, U>::baz) {} // { dg-error "" }
};
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