crash16.C: Function name is the correct location for an error regarding a function.

testsuite/
        * g++.old-deja/g++.brendan/crash16.C: Function name is the correct 
        location for an error regarding a function.
        * g++.old-deja/g++.other/pmf3.C: Same.
        * g++.old-deja/g++.law/ctors5.C: Same.
        * g++.old-deja/g++.pt/explicit34.C: Same.
        * g++.dg/parse/error28.C: Same.
        * g++.dg/parse/error17.C: Same.
        * g++.dg/template/friend44.C: Same.
cp/
        * decl.c (duplicate_decls): Call error_at.
        (grokfndecl): New location argument.  Use location if available.
        (grokdeclarator): Pass declarator location to grokfndecl.
        * cp-tree.h (struct cp_declarator): Update comment for id_loc.
        * decl2.c (check_classfn): Use error_at.
        * parser.c (cp_parser_init_declarator): Set function_start_locus
        to brace location.
        (cp_parser_member_declaration): Set id_loc for function declarators.

From-SVN: r140379
This commit is contained in:
Aldy Hernandez 2008-09-15 22:24:18 +00:00 committed by Aldy Hernandez
parent 0eeb22402c
commit 402b8cf659
13 changed files with 66 additions and 19 deletions

View File

@ -1,3 +1,14 @@
2008-09-15 Aldy Hernandez <aldyh@redhat.com>
* decl.c (duplicate_decls): Call error_at.
(grokfndecl): New location argument. Use location if available.
(grokdeclarator): Pass declarator location to grokfndecl.
* cp-tree.h (struct cp_declarator): Update comment for id_loc.
* decl2.c (check_classfn): Use error_at.
* parser.c (cp_parser_init_declarator): Set function_start_locus
to brace location.
(cp_parser_member_declaration): Set id_loc for function declarators.
2008-09-09 Jan Hubicka <jh@suse.cz> 2008-09-09 Jan Hubicka <jh@suse.cz>
PR middle-end/37500 PR middle-end/37500

View File

@ -4089,7 +4089,7 @@ struct cp_declarator {
/* For all but cdk_id and cdk_error, the contained declarator. For /* For all but cdk_id and cdk_error, the contained declarator. For
cdk_id and cdk_error, guaranteed to be NULL. */ cdk_id and cdk_error, guaranteed to be NULL. */
cp_declarator *declarator; cp_declarator *declarator;
location_t id_loc; /* Currently only set for cdk_id. */ location_t id_loc; /* Currently only set for cdk_id and cdk_function. */
union { union {
/* For identifiers. */ /* For identifiers. */
struct { struct {

View File

@ -1459,7 +1459,7 @@ duplicate_decls (tree newdecl, tree olddecl, bool newdecl_is_friend)
const char *errmsg = redeclaration_error_message (newdecl, olddecl); const char *errmsg = redeclaration_error_message (newdecl, olddecl);
if (errmsg) if (errmsg)
{ {
error (errmsg, newdecl); error_at (DECL_SOURCE_LOCATION (newdecl), errmsg, newdecl);
if (DECL_NAME (olddecl) != NULL_TREE) if (DECL_NAME (olddecl) != NULL_TREE)
error ((DECL_INITIAL (olddecl) && namespace_bindings_p ()) error ((DECL_INITIAL (olddecl) && namespace_bindings_p ())
? "%q+#D previously defined here" ? "%q+#D previously defined here"
@ -6497,7 +6497,8 @@ grokfndecl (tree ctype,
bool funcdef_flag, bool funcdef_flag,
int template_count, int template_count,
tree in_namespace, tree in_namespace,
tree* attrlist) tree* attrlist,
location_t location)
{ {
tree decl; tree decl;
int staticp = ctype && TREE_CODE (type) == FUNCTION_TYPE; int staticp = ctype && TREE_CODE (type) == FUNCTION_TYPE;
@ -6507,6 +6508,12 @@ grokfndecl (tree ctype,
type = build_exception_variant (type, raises); type = build_exception_variant (type, raises);
decl = build_lang_decl (FUNCTION_DECL, declarator, type); decl = build_lang_decl (FUNCTION_DECL, declarator, type);
/* If we have an explicit location, use it, otherwise use whatever
build_lang_decl used (probably input_location). */
if (location != UNKNOWN_LOCATION)
DECL_SOURCE_LOCATION (decl) = location;
if (TREE_CODE (type) == METHOD_TYPE) if (TREE_CODE (type) == METHOD_TYPE)
{ {
tree parm; tree parm;
@ -9018,7 +9025,8 @@ grokdeclarator (const cp_declarator *declarator,
virtualp, flags, memfn_quals, raises, virtualp, flags, memfn_quals, raises,
friendp ? -1 : 0, friendp, publicp, inlinep, friendp ? -1 : 0, friendp, publicp, inlinep,
sfk, sfk,
funcdef_flag, template_count, in_namespace, attrlist); funcdef_flag, template_count, in_namespace,
attrlist, declarator->id_loc);
if (decl == NULL_TREE) if (decl == NULL_TREE)
return error_mark_node; return error_mark_node;
#if 0 #if 0
@ -9060,7 +9068,8 @@ grokdeclarator (const cp_declarator *declarator,
virtualp, flags, memfn_quals, raises, virtualp, flags, memfn_quals, raises,
friendp ? -1 : 0, friendp, 1, 0, sfk, friendp ? -1 : 0, friendp, 1, 0, sfk,
funcdef_flag, template_count, in_namespace, funcdef_flag, template_count, in_namespace,
attrlist); attrlist,
declarator->id_loc);
if (decl == NULL_TREE) if (decl == NULL_TREE)
return error_mark_node; return error_mark_node;
} }
@ -9255,7 +9264,8 @@ grokdeclarator (const cp_declarator *declarator,
virtualp, flags, memfn_quals, raises, virtualp, flags, memfn_quals, raises,
1, friendp, 1, friendp,
publicp, inlinep, sfk, funcdef_flag, publicp, inlinep, sfk, funcdef_flag,
template_count, in_namespace, attrlist); template_count, in_namespace, attrlist,
declarator->id_loc);
if (decl == NULL_TREE) if (decl == NULL_TREE)
return error_mark_node; return error_mark_node;

View File

@ -638,7 +638,8 @@ check_classfn (tree ctype, tree function, tree template_parms)
return OVL_CURRENT (fndecls); return OVL_CURRENT (fndecls);
} }
error ("prototype for %q#D does not match any in class %qT", error_at (DECL_SOURCE_LOCATION (function),
"prototype for %q#D does not match any in class %qT",
function, ctype); function, ctype);
is_conv_op = DECL_CONV_FN_P (fndecl); is_conv_op = DECL_CONV_FN_P (fndecl);

View File

@ -12563,6 +12563,9 @@ cp_parser_init_declarator (cp_parser* parser,
} }
else else
{ {
location_t func_brace_location
= cp_lexer_peek_token (parser->lexer)->location;
/* Neither attributes nor an asm-specification are allowed /* Neither attributes nor an asm-specification are allowed
on a function-definition. */ on a function-definition. */
if (asm_specification) if (asm_specification)
@ -12586,6 +12589,13 @@ cp_parser_init_declarator (cp_parser* parser,
= (cp_parser_function_definition_from_specifiers_and_declarator = (cp_parser_function_definition_from_specifiers_and_declarator
(parser, decl_specifiers, prefix_attributes, declarator)); (parser, decl_specifiers, prefix_attributes, declarator));
if (decl != error_mark_node && DECL_STRUCT_FUNCTION (decl))
{
/* This is where the prologue starts... */
DECL_STRUCT_FUNCTION (decl)->function_start_locus
= func_brace_location;
}
return decl; return decl;
} }
} }
@ -15791,6 +15801,8 @@ cp_parser_member_declaration (cp_parser* parser)
return; return;
} }
else else
if (declarator->kind == cdk_function)
declarator->id_loc = token->location;
/* Create the declaration. */ /* Create the declaration. */
decl = grokfield (declarator, &decl_specifiers, decl = grokfield (declarator, &decl_specifiers,
initializer, /*init_const_expr_p=*/true, initializer, /*init_const_expr_p=*/true,

View File

@ -1,3 +1,14 @@
2008-09-15 Aldy Hernandez <aldyh@redhat.com>
* g++.old-deja/g++.brendan/crash16.C: Function name is the correct
location for an error regarding a function.
* g++.old-deja/g++.other/pmf3.C: Same.
* g++.old-deja/g++.law/ctors5.C: Same.
* g++.old-deja/g++.pt/explicit34.C: Same.
* g++.dg/parse/error28.C: Same.
* g++.dg/parse/error17.C: Same.
* g++.dg/template/friend44.C: Same.
2008-09-13 Raksit Ashok <raksit@google.com> 2008-09-13 Raksit Ashok <raksit@google.com>
PR rtl-optimization/37489 PR rtl-optimization/37489

View File

@ -2,7 +2,7 @@
// PR c++/16965 // PR c++/16965
template <typename T> struct B { template <typename T> struct B {
static int Bar(T); // { dg-error "19: error: candidates are: |19: error: " } static int Bar(T); // { dg-error "14: error: candidates are: |14: error: " }
}; };
struct D : B<int>, B<char> {}; struct D : B<int>, B<char> {};

View File

@ -3,7 +3,7 @@
struct virt { virt () {} virt (int i) {} }; struct virt { virt () {} virt (int i) {} };
struct der : public virtual virt { // { dg-error "34: note: der::der" } struct der : public virtual virt { // { dg-error "34: note: der::der" }
der (int i) : virt(i) {} // { dg-error "13: note: candidates are: der" } der (int i) : virt(i) {} // { dg-error "3: note: candidates are: der" }
}; };
struct top : public der { struct top : public der {
top () {} // { dg-bogus "der\\(const" } top () {} // { dg-bogus "der\\(const" }

View File

@ -1,8 +1,9 @@
// { dg-options "-fshow-column" }
//PR c++/28260 //PR c++/28260
template<int> struct A template<int> struct A
{ {
friend int foo(); // { dg-error "new declaration" } friend int foo(); // { dg-error "14: error: new declaration" }
}; };
void foo() { A<0> a; } // { dg-error "ambiguates old declaration" } void foo() { A<0> a; } // { dg-error "6: error: ambiguates old declaration" }

View File

@ -5,10 +5,10 @@
class Graph { // { dg-error "1: error: new types|1: note: \\(perhaps" } class Graph { // { dg-error "1: error: new types|1: note: \\(perhaps" }
public: public:
unsigned char N; unsigned char N;
Graph(void) {} // { dg-error "17: error: 'Graph" } Graph(void) {} // { dg-error "7: error: 'Graph" }
} }
Graph::Graph(void) // { dg-error "18: error: return type|18: error: redefinition" } Graph::Graph(void) // { dg-error "18: error: return type|1: error: redefinition" }
{ N = 10; { N = 10;
} }

View File

@ -21,7 +21,7 @@ class Y // { dg-error "1: error: new types may not be defined in a return type|1
public: public:
Y(); Y();
} }
X::X( int xi ) // { dg-error "14: error: return type specification for constructor invalid|14: note: candidates are: X::X\\(int\\)" } X::X( int xi ) // { dg-error "14: error: return type specification for constructor invalid|1: note: candidates are: X::X\\(int\\)" }
{ {
x = xi; x = xi;
} }

View File

@ -3,9 +3,9 @@
// Bug: g++ was crashing after giving errors. // Bug: g++ was crashing after giving errors.
template<class T> template<class T>
void connect_to_method( void connect_to_method( // { dg-error "candidates are" }
T *receiver, T *receiver,
void (T::*method)()) // { dg-error "candidates are" } void (T::*method)())
{} {}
class Gtk_Base class Gtk_Base

View File

@ -1,10 +1,11 @@
// { dg-do assemble } // { dg-do assemble }
// { dg-options "-fshow-column" }
// GROUPS passed templates // GROUPS passed templates
template <class T> template <class T>
void foo(T t); void foo(T t);
template <> template <>
void foo(int) {}; // { dg-error "" } previously defined here. void foo(int) {}; // { dg-error "6:" } previously defined here.
template <> template <>
void foo<int>(int) {} // { dg-error "" } duplicate specialization. void foo<int>(int) {} // { dg-error "6:" } duplicate specialization.