+2016-05-30 Paolo Carlini <paolo.carlini@oracle.com>
+
+ PR c++/71238
+ * lex.c (unqualified_name_lookup_error): Take a location too.
+ (unqualified_fn_lookup_error): Take a cp_expr.
+ * cp-tree.h (unqualified_name_lookup_error,
+ unqualified_fn_lookup_error): Adjust declarations.
+ * semantics.c (perform_koenig_lookup): Adjust
+ unqualified_fn_lookup_error call, pass the location of
+ the identifier too as part of a cp_expr.
+
2016-05-30 Paolo Carlini <paolo.carlini@oracle.com>
PR c++/71099
extern void cxx_dup_lang_specific_decl (tree);
extern void yyungetc (int, int);
-extern tree unqualified_name_lookup_error (tree);
-extern tree unqualified_fn_lookup_error (tree);
+extern tree unqualified_name_lookup_error (tree,
+ location_t = UNKNOWN_LOCATION);
+extern tree unqualified_fn_lookup_error (cp_expr);
extern tree build_lang_decl (enum tree_code, tree, tree);
extern tree build_lang_decl_loc (location_t, enum tree_code, tree, tree);
extern void retrofit_lang_decl (tree);
IDENTIFIER_NODE) failed. Returns the ERROR_MARK_NODE. */
tree
-unqualified_name_lookup_error (tree name)
+unqualified_name_lookup_error (tree name, location_t loc)
{
+ if (loc == UNKNOWN_LOCATION)
+ loc = EXPR_LOC_OR_LOC (name, input_location);
+
if (IDENTIFIER_OPNAME_P (name))
{
if (name != ansi_opname (ERROR_MARK))
- error ("%qD not defined", name);
+ error_at (loc, "%qD not defined", name);
}
else
{
if (!objc_diagnose_private_ivar (name))
{
- error ("%qD was not declared in this scope", name);
- suggest_alternatives_for (location_of (name), name);
+ error_at (loc, "%qD was not declared in this scope", name);
+ suggest_alternatives_for (loc, name);
}
/* Prevent repeated error messages by creating a VAR_DECL with
this NAME in the innermost block scope. */
if (local_bindings_p ())
{
tree decl;
- decl = build_decl (input_location,
- VAR_DECL, name, error_mark_node);
+ decl = build_decl (loc, VAR_DECL, name, error_mark_node);
DECL_CONTEXT (decl) = current_function_decl;
push_local_binding (name, decl, 0);
/* Mark the variable as used so that we do not get warnings
return error_mark_node;
}
-/* Like unqualified_name_lookup_error, but NAME is an unqualified-id
- used as a function. Returns an appropriate expression for
- NAME. */
+/* Like unqualified_name_lookup_error, but NAME_EXPR is an unqualified-id
+ NAME, encapsulated with its location in a CP_EXPR, used as a function.
+ Returns an appropriate expression for NAME. */
tree
-unqualified_fn_lookup_error (tree name)
+unqualified_fn_lookup_error (cp_expr name_expr)
{
+ tree name = name_expr.get_value ();
+ location_t loc = name_expr.get_location ();
+ if (loc == UNKNOWN_LOCATION)
+ loc = input_location;
+
if (processing_template_decl)
{
/* In a template, it is invalid to write "f()" or "f(3)" if no
Note that we have the exact wording of the following message in
the manual (trouble.texi, node "Name lookup"), so they need to
be kept in synch. */
- permerror (input_location, "there are no arguments to %qD that depend on a template "
+ permerror (loc, "there are no arguments to %qD that depend on a template "
"parameter, so a declaration of %qD must be available",
name, name);
static bool hint;
if (!hint)
{
- inform (input_location, "(if you use %<-fpermissive%>, G++ will accept your "
+ inform (loc, "(if you use %<-fpermissive%>, G++ will accept your "
"code, but allowing the use of an undeclared name is "
"deprecated)");
hint = true;
return name;
}
- return unqualified_name_lookup_error (name);
+ return unqualified_name_lookup_error (name, loc);
}
/* Wrapper around build_lang_decl_loc(). Should gradually move to
tree functions = NULL_TREE;
tree tmpl_args = NULL_TREE;
bool template_id = false;
+ location_t loc = fn.get_location ();
if (TREE_CODE (fn) == TEMPLATE_ID_EXPR)
{
{
/* The unqualified name could not be resolved. */
if (complain)
- fn = unqualified_fn_lookup_error (identifier);
+ fn = unqualified_fn_lookup_error (cp_expr (identifier, loc));
else
fn = identifier;
}
+2016-05-30 Paolo Carlini <paolo.carlini@oracle.com>
+
+ PR c++/71238
+ * g++.dg/parse/pr71238.C: New.
+ * g++.dg/concepts/friend1.C: Test column numbers too.
+ * g++.dg/cpp0x/initlist31.C: Likewise.
+ * g++.dg/cpp0x/pr51420.C: Likewise.
+ * g++.dg/cpp0x/udlit-declare-neg.C: Likewise.
+ * g++.dg/cpp0x/udlit-member-neg.C: Likewise.
+ * g++.dg/ext/builtin3.C: Likewise.
+ * g++.dg/lookup/friend12.C: Likewise.
+ * g++.dg/lookup/friend7.C: Likewise.
+ * g++.dg/lookup/koenig1.C: Likewise.
+ * g++.dg/lookup/koenig5.C: Likewise.
+ * g++.dg/lookup/used-before-declaration.C: Likewise.
+ * g++.dg/overload/koenig1.C: Likewise.
+ * g++.dg/template/crash65.C: Likewise.
+ * g++.dg/template/friend57.C: Likewise.
+ * g++.dg/warn/Wshadow-5.C: Likewise.
+ * g++.dg/warn/Wunused-8.C: Likewise.
+ * g++.old-deja/g++.bugs/900211_01.C: Likewise.
+ * g++.old-deja/g++.jason/lineno5.C: Likewise.
+ * g++.old-deja/g++.jason/member.C: Likewise.
+ * g++.old-deja/g++.jason/report.C: Likewise.
+ * g++.old-deja/g++.jason/scoping12.C: Likewise.
+ * g++.old-deja/g++.law/visibility20.C: Likewise.
+ * g++.old-deja/g++.ns/koenig5.C: Likewise.
+ * g++.old-deja/g++.other/static5.C: Likewise.
+ * g++.old-deja/g++.pt/overload2.C: Likewise.
+
2016-05-30 Jan Hubicka <hubicka@ucw.cz>
* gcc.dg/tree-ssa/peel1.c: New testcase.
int main() {
// f(0); // OK
f(nt); // { dg-error "cannot call" }
- f(x); // { dg-error "not declared" }
+ f(x); // { dg-error "3:'f' was not declared" }
S<int> si;
si == si; // OK
void f() {
auto y =
{
- string(Equation()) // { dg-error "not declared" }
+ string(Equation()) // { dg-error "12:'Equation' was not declared" }
}; // { dg-error "unable to deduce" }
}
void
foo()
{
- float x = operator"" _F(); // { dg-error "was not declared in this scope" }
+ float x = operator"" _F(); // { dg-error "13:'operator\"\"_F' was not declared in this scope" }
float y = 0_F; // { dg-error "unable to find numeric literal operator" }
}
// Check that undeclared literal operator calls and literals give appropriate errors.
-int i = operator"" _Bar('x'); // { dg-error "was not declared in this scope" }
+int i = operator"" _Bar('x'); // { dg-error "9:'operator\"\"_Bar' was not declared in this scope" }
int j = 'x'_Bar; // { dg-error "unable to find character literal operator|with|argument" }
-int ii = operator"" _BarCharStr("Howdy, Pardner!"); // { dg-error "was not declared in this scope" }
+int ii = operator"" _BarCharStr("Howdy, Pardner!"); // { dg-error "10:'operator\"\"_BarCharStr' was not declared in this scope" }
int jj = "Howdy, Pardner!"_BarCharStr; // { dg-error "unable to find string literal operator|Possible missing length argument" }
-unsigned long long iULL = operator"" _BarULL(666ULL); // { dg-error "was not declared in this scope" }
+unsigned long long iULL = operator"" _BarULL(666ULL); // { dg-error "27:'operator\"\"_BarULL' was not declared in this scope" }
unsigned long long jULL = 666_BarULL; // { dg-error "unable to find numeric literal operator" }
-long double iLD = operator"" _BarLD(666.0L); // { dg-error "was not declared in this scope" }
+long double iLD = operator"" _BarLD(666.0L); // { dg-error "19:'operator\"\"_BarLD' was not declared in this scope" }
long double jLD = 666.0_BarLD; // { dg-error "unable to find numeric literal operator" }
int operator"" _Bar(char32_t); // { dg-error "must be a non-member function" }
};
-int i = operator"" _Bar(U'x'); // { dg-error "was not declared in this scope" }
+int i = operator"" _Bar(U'x'); // { dg-error "9:'operator\"\"_Bar' was not declared in this scope" }
int j = U'x'_Bar; // { dg-error "unable to find character literal operator" }
int
}
void foo() {
- printf("abc"); // { dg-error "not declared" }
+ printf("abc"); // { dg-error "3:'printf' was not declared" }
// { dg-message "suggested alternative" "suggested alternative" { target *-*-* } 12 }
}
{
friend void bar(); // { dg-error "without prior declaration" }
};
- bar(); // { dg-error "not declared" }
+ bar(); // { dg-error "3:'bar' was not declared" }
}
struct S { friend void g(); friend void h(S); };
struct T { friend void g(); friend void h(T); };
void i() {
- g(); // { dg-error "not declared" }
+ g(); // { dg-error "3:'g' was not declared" }
S s;
h(s);
T t;
void foo() {
X x(1); // { dg-error "incomplete type" "" }
- bar(x); // { dg-error "not declared" "" }
+ bar(x); // { dg-error "3:'bar' was not declared" "" }
}
{
One (a); // ok
One (a, b); // ok
- One (b); // { dg-error "not declared" }
+ One (b); // { dg-error "3:'One' was not declared" }
// { dg-message "suggested alternatives" "suggested alternative for One" { target *-*-* } 34 }
Two (c); // ok
Two (a, c); // ok
- Two (a); // { dg-error "not declared" }
+ Two (a); // { dg-error "3:'Two' was not declared" }
// { dg-message "suggested alternatives" "suggested alternative for Two" { target *-*-* } 39 }
Two (a, a); // error masked by earlier error
Two (b); // error masked by earlier error
Three (b); // ok
Three (a, b); // ok
- Three (a); // { dg-error "not declared" }
+ Three (a); // { dg-error "3:'Three' was not declared" }
// { dg-message "suggested alternatives" "suggested alternative for Three" { target *-*-* } 47 }
}
// Copyroght (C) 2003 Free Software Foundation
// Origin: PR/12832, Jonathan Wakely <redi@gcc.gnu.org>
-void f() { g(); } // { dg-error "not declared" "" }
+void f() { g(); } // { dg-error "12:'g' was not declared" "" }
void g() { }
{
B *bp;
N::A *ap;
- f (bp); // { dg-error "not declared" }
+ f (bp); // { dg-error "3:'f' was not declared" }
// { dg-message "suggested alternative" "suggested alternative" { target *-*-* } 16 }
f (ap);
}
--- /dev/null
+// PR c++/71238
+
+int main()
+{
+ int x=myFunc(3234); // { dg-error "11:'myFunc' was not declared" }
+}
struct A
{
template<int> template<typename T> friend void foo(T) {} // { dg-error "parameter" }
- void bar() { foo(0); } // { dg-error "foo" }
+ void bar() { foo(0); } // { dg-error "16:'foo' was not declared" }
};
main ()
{
f(1);
- g(1); // { dg-error "'g' was not declared in this scope" }
+ g(1); // { dg-error "3:'g' was not declared in this scope" }
g(S());
h(1);
}
int f (int n)
{
int bar (int n) { return n++; } // { dg-error "a function-definition is not allowed here" }
- return bar (n); // { dg-error "was not declared in this scope" }
+ return bar (n); // { dg-error "12:'bar' was not declared in this scope" }
}
int g (int i)
{
// We should not see an "unused" warning about "whatever" on the
// next line.
- return whatever (); // { dg-error "declared" }
+ return whatever (); // { dg-error "10:'whatever' was not declared" }
}
void global_function_0 ()
{
- global_function_1 (); /* { dg-error "" } */
+ global_function_1 (); /* { dg-error "3:'global_function_1' was not declared" } */
}
int main () { return 0; }
int main()
{
A<int> *p;
- undef1();// { dg-error "" }
+ undef1();// { dg-error "3:'undef1' was not declared" }
}
struct X
{
int A;
- int Y::X::* foo () { undef1(1); return &Y::X::A; }// { dg-error "" } foo().*
+ int Y::X::* foo () { undef1(1); return &Y::X::A; }// { dg-error "28:'undef1' was not declared" } foo().*
int bar () { return A; }
};
};
int Y::X::* foo ()
{
- undef2(1);// { dg-error "" } foo().*
+ undef2(1);// { dg-error "3:'undef2' was not declared" } foo().*
return &Y::X::A;
}
int Y::X::* (* foo2 ())()
{
- undef3(1);// { dg-error "" } foo().*
+ undef3(1);// { dg-error "3:'undef3' was not declared" } foo().*
return foo;
}
int (Y::X::* bar2 ()) ()
{
- undef4(1);// { dg-error "" } foo\(\).*
+ undef4(1);// { dg-error "3:'undef4' was not declared" } foo\(\).*
return Y::X::bar;// { dg-error "" } foo\(\).*
}
int Y::X::* (Y::X::* foo3 ())()
{
- undef5(1);// { dg-error "" } foo().*
+ undef5(1);// { dg-error "3:'undef5' was not declared" } foo().*
return Y::X::foo;// { dg-error "" } foo().*
}
int foo2 (int (*a)(int) = &foo)
{
- undef4 (1); // { dg-error "" } implicit declaration
+ undef4 (1); // { dg-error "4:'undef4' was not declared" } implicit declaration
return 1;
}
X::Y f; // { dg-error "" } in this context
bar2 wa [5];
wa[0] = baz(f);
- undef2 (1); // { dg-error "" } implicit declaration
+ undef2 (1); // { dg-error "3:'undef2' was not declared" } implicit declaration
} // { dg-warning "no return statement" }
int ninny ()
int darg (char X::*p)
{
- undef3 (1); // { dg-error "" } implicit declaration
+ undef3 (1); // { dg-error "4:'undef3' was not declared" } implicit declaration
} // { dg-warning "no return statement" }
};
}
void h () {
- g (); // { dg-error "" } no g in scope
+ g (); // { dg-error "3:'g' was not declared" } no g in scope
}
Base b;
Derived d;
d.noticeThisFunction(&b);
- printf("gpptest run\n");// { dg-error "" } .*
+ printf("gpptest run\n");// { dg-error "5:'printf' was not declared" } .*
}
foo(new X); // ok -- DR 218 says that we find the global
// foo variable first, and therefore do not
// perform argument-dependent lookup.
- bar(new X); // { dg-error "not declared" }
+ bar(new X); // { dg-error "3:'bar' was not declared" }
// { dg-message "suggested alternative" "suggested alternative" { target *-*-* } 17 }
}
inline void f()
{
static S s;
- atexit (0); // { dg-error "" } implicit declaration
+ atexit (0); // { dg-error "3:'atexit' was not declared" } implicit declaration
}
main()
{
C<char*> c;
- char* p = Z(c.O); //{ dg-error "" } ambiguous c.O
+ char* p = Z(c.O); //{ dg-error "13:'Z' was not declared" } ambiguous c.O
}