tree argtypes = TYPE_ARG_TYPES (TREE_TYPE (decl));
bool methodp = TREE_CODE (TREE_TYPE (decl)) == METHOD_TYPE;
tree name = DECL_NAME (decl);
+ location_t loc = DECL_SOURCE_LOCATION (decl);
tree class_type = DECL_CONTEXT (decl);
if (class_type && !CLASS_TYPE_P (class_type))
{
if (CP_DECL_CONTEXT (decl) != global_namespace)
{
- error ("%qD may not be declared within a namespace", decl);
+ error_at (loc, "%qD may not be declared within a namespace",
+ decl);
return false;
}
if (!TREE_PUBLIC (decl))
{
- error ("%qD may not be declared as static", decl);
+ error_at (loc, "%qD may not be declared as static", decl);
return false;
}
}
|| operator_code == ARRAY_REF
|| operator_code == NOP_EXPR)
{
- error ("%qD must be a nonstatic member function", decl);
+ error_at (loc, "%qD must be a nonstatic member function", decl);
return false;
}
if (DECL_STATIC_FUNCTION_P (decl))
{
- error ("%qD must be either a non-static member "
- "function or a non-member function", decl);
+ error_at (loc, "%qD must be either a non-static member "
+ "function or a non-member function", decl);
return false;
}
if (!arg || arg == void_list_node)
{
if (complain)
- error ("%qD must have an argument of class or "
- "enumerated type", decl);
+ error_at(loc, "%qD must have an argument of class or "
+ "enumerated type", decl);
return false;
}
if (operator_code == COND_EXPR)
{
/* 13.4.0.3 */
- error ("ISO C++ prohibits overloading operator ?:");
+ error_at (loc, "ISO C++ prohibits overloading operator ?:");
return false;
}
if (!arg)
{
/* Variadic. */
- error ("%qD must not have variable number of arguments", decl);
+ error_at (loc, "%qD must not have variable number of arguments",
+ decl);
return false;
}
++arity;
else if (arity != 2)
{
/* This was an ambiguous operator but is invalid. */
- error (methodp
- ? G_("%qD must have either zero or one argument")
- : G_("%qD must have either one or two arguments"), decl);
+ error_at (loc,
+ methodp
+ ? G_("%qD must have either zero or one argument")
+ : G_("%qD must have either one or two arguments"), decl);
return false;
}
else if ((operator_code == POSTINCREMENT_EXPR
&& ! same_type_p (TREE_VALUE (TREE_CHAIN (argtypes)),
integer_type_node))
{
- error (methodp
- ? G_("postfix %qD must have %<int%> as its argument")
- : G_("postfix %qD must have %<int%> as its second argument"),
- decl);
+ error_at (loc,
+ methodp
+ ? G_("postfix %qD must have %<int%> as its argument")
+ : G_("postfix %qD must have %<int%> as its second argument"),
+ decl);
return false;
}
break;
case OVL_OP_FLAG_UNARY:
if (arity != 1)
{
- error (methodp
- ? G_("%qD must have no arguments")
- : G_("%qD must have exactly one argument"), decl);
+ error_at (loc,
+ methodp
+ ? G_("%qD must have no arguments")
+ : G_("%qD must have exactly one argument"), decl);
return false;
}
break;
case OVL_OP_FLAG_BINARY:
if (arity != 2)
{
- error (methodp
- ? G_("%qD must have exactly one argument")
- : G_("%qD must have exactly two arguments"), decl);
+ error_at (loc,
+ methodp
+ ? G_("%qD must have exactly one argument")
+ : G_("%qD must have exactly two arguments"), decl);
return false;
}
break;
if (TREE_PURPOSE (arg))
{
TREE_PURPOSE (arg) = NULL_TREE;
- if (operator_code == POSTINCREMENT_EXPR
- || operator_code == POSTDECREMENT_EXPR)
- pedwarn (input_location, OPT_Wpedantic,
- "%qD cannot have default arguments", decl);
- else
- {
- error ("%qD cannot have default arguments", decl);
- return false;
- }
+ error_at (loc, "%qD cannot have default arguments", decl);
+ return false;
}
/* At this point the declaration is well-formed. It may not be
t = TYPE_MAIN_VARIANT (TREE_TYPE (t));
if (VOID_TYPE_P (t))
- warning (OPT_Wconversion,
- ref
- ? G_("conversion to a reference to void "
- "will never use a type conversion operator")
- : G_("conversion to void "
- "will never use a type conversion operator"));
+ warning_at (loc, OPT_Wconversion,
+ ref
+ ? G_("conversion to a reference to void "
+ "will never use a type conversion operator")
+ : G_("conversion to void "
+ "will never use a type conversion operator"));
else if (class_type)
{
if (t == class_type)
- warning (OPT_Wconversion,
- ref
- ? G_("conversion to a reference to the same type "
- "will never use a type conversion operator")
- : G_("conversion to the same type "
- "will never use a type conversion operator"));
+ warning_at (loc, OPT_Wconversion,
+ ref
+ ? G_("conversion to a reference to the same type "
+ "will never use a type conversion operator")
+ : G_("conversion to the same type "
+ "will never use a type conversion operator"));
/* Don't force t to be complete here. */
else if (MAYBE_CLASS_TYPE_P (t)
&& COMPLETE_TYPE_P (t)
&& DERIVED_FROM_P (t, class_type))
- warning (OPT_Wconversion,
- ref
- ? G_("conversion to a reference to a base class "
- "will never use a type conversion operator")
- : G_("conversion to a base class "
- "will never use a type conversion operator"));
+ warning_at (loc, OPT_Wconversion,
+ ref
+ ? G_("conversion to a reference to a base class "
+ "will never use a type conversion operator")
+ : G_("conversion to a base class "
+ "will never use a type conversion operator"));
}
}
if (operator_code == TRUTH_ANDIF_EXPR
|| operator_code == TRUTH_ORIF_EXPR
|| operator_code == COMPOUND_EXPR)
- warning (OPT_Weffc__,
- "user-defined %qD always evaluates both arguments", decl);
+ warning_at (loc, OPT_Weffc__,
+ "user-defined %qD always evaluates both arguments", decl);
/* More Effective C++ rule 6. */
if (operator_code == POSTINCREMENT_EXPR
{
if (!TYPE_REF_P (ret)
|| !same_type_p (TYPE_MAIN_VARIANT (TREE_TYPE (ret)), arg))
- warning (OPT_Weffc__, "prefix %qD should return %qT", decl,
- build_reference_type (arg));
+ warning_at (loc, OPT_Weffc__, "prefix %qD should return %qT", decl,
+ build_reference_type (arg));
}
else
{
if (!same_type_p (TYPE_MAIN_VARIANT (ret), arg))
- warning (OPT_Weffc__, "postfix %qD should return %qT", decl, arg);
+ warning_at (loc, OPT_Weffc__,
+ "postfix %qD should return %qT", decl, arg);
}
}
|| operator_code == MULT_EXPR
|| operator_code == TRUNC_MOD_EXPR)
&& TYPE_REF_P (TREE_TYPE (TREE_TYPE (decl))))
- warning (OPT_Weffc__, "%qD should return by value", decl);
+ warning_at (loc, OPT_Weffc__, "%qD should return by value", decl);
return true;
}
struct A {
int operator?:(int a, int b); // { dg-error "expected type-specifier" }
- static int operator()(int a); // { dg-error "must be a nonstatic member" }
- static int operator+(A,A); // { dg-error "either a non-static member" }
- int operator+(int a, int b = 1); // { dg-error "either zero or one" }
- int operator++(char); // { dg-error "must have 'int'" }
+ static int operator()(int a); // { dg-error "14:.static int A::operator\\(\\)\\(int\\). must be a nonstatic member function" }
+ static int operator+(A,A); // { dg-error "14:.static int A::operator\\+\\(A, A\\). must be either a non-static member function or a non-member function" }
+ int operator+(int a, int b = 1); // { dg-error "7:.int A::operator\\+\\(int, int\\). must have either zero or one argument" }
+ int operator++(char); // { dg-error "7:postfix .int A::operator\\+\\+\\(char\\). must have .int. as its argument" }
void operator delete (void *);
void operator delete (void *, unsigned long);
};
struct B {
void * operator new (size_t, void *);
- int operator++(int = 0);
+ int operator++(int = 0); // { dg-error "7:.int B::operator\\+\\+\\(int\\). cannot have default arguments" }
int operator+ (int);
void operator()();
char * operator[](int);
B * operator->();
};
-int operator-(int a, int b); // { dg-error "argument of class or" }
+int operator-(int a, int b); // { dg-error "5:.int operator-\\(int, int\\). must have an argument of class or enumerated type" }
void * operator new (A a); // { dg-error "first parameter" }
void operator delete (A a); // { dg-error "first parameter" }
char * operator char * (int); // { dg-error "return type" "ret" }
-// { dg-error "nonstatic member function" "mem" { target *-*-* } .-1 }
+// { dg-error "8:.operator char\\*\\*\\(int\\). must be a nonstatic member function" "mem" { target *-*-* } .-1 }