+2019-11-26 Paolo Carlini <paolo.carlini@oracle.com>
+
+ * typeck.c (cp_build_unary_op): Consistently use the accurate
+ location in seven additional diagnostic messages.
+ (cp_build_compound_expr): Use cp_expr_loc_or_input_loc in one place.
+
2019-11-26 Jakub Jelinek <jakub@redhat.com>
PR c++/92648
if (TREE_CODE (argtype) == ENUMERAL_TYPE)
{
if (complain & tf_error)
- permerror (input_location, (code == PREINCREMENT_EXPR || code == POSTINCREMENT_EXPR)
+ permerror (location, (code == PREINCREMENT_EXPR
+ || code == POSTINCREMENT_EXPR)
? G_("ISO C++ forbids incrementing an enum")
: G_("ISO C++ forbids decrementing an enum"));
else
if (!COMPLETE_OR_VOID_TYPE_P (type))
{
if (complain & tf_error)
- error (((code == PREINCREMENT_EXPR
- || code == POSTINCREMENT_EXPR))
- ? G_("cannot increment a pointer to incomplete type %qT")
- : G_("cannot decrement a pointer to incomplete type %qT"),
- TREE_TYPE (argtype));
+ error_at (location, ((code == PREINCREMENT_EXPR
+ || code == POSTINCREMENT_EXPR))
+ ? G_("cannot increment a pointer to incomplete "
+ "type %qT")
+ : G_("cannot decrement a pointer to incomplete "
+ "type %qT"),
+ TREE_TYPE (argtype));
else
return error_mark_node;
}
else if (!TYPE_PTROB_P (argtype))
{
if (complain & tf_error)
- pedwarn (input_location, OPT_Wpointer_arith,
+ pedwarn (location, OPT_Wpointer_arith,
(code == PREINCREMENT_EXPR
|| code == POSTINCREMENT_EXPR)
- ? G_("ISO C++ forbids incrementing a pointer of type %qT")
- : G_("ISO C++ forbids decrementing a pointer of type %qT"),
+ ? G_("ISO C++ forbids incrementing a pointer "
+ "of type %qT")
+ : G_("ISO C++ forbids decrementing a pointer "
+ "of type %qT"),
argtype);
else
return error_mark_node;
if (code == POSTDECREMENT_EXPR || code == PREDECREMENT_EXPR)
{
if (complain & tf_error)
- error ("use of an operand of type %qT in %<operator--%> "
- "is forbidden", boolean_type_node);
+ error_at (location,
+ "use of an operand of type %qT in %<operator--%> "
+ "is forbidden", boolean_type_node);
return error_mark_node;
}
else
if (cxx_dialect >= cxx17)
{
if (complain & tf_error)
- error ("use of an operand of type %qT in "
- "%<operator++%> is forbidden in C++17",
- boolean_type_node);
+ error_at (location,
+ "use of an operand of type %qT in "
+ "%<operator++%> is forbidden in C++17",
+ boolean_type_node);
return error_mark_node;
}
/* Otherwise, [depr.incr.bool] says this is deprecated. */
else
- warning (OPT_Wdeprecated, "use of an operand of type %qT "
- "in %<operator++%> is deprecated",
- boolean_type_node);
+ warning_at (location, OPT_Wdeprecated,
+ "use of an operand of type %qT "
+ "in %<operator++%> is deprecated",
+ boolean_type_node);
}
val = boolean_increment (code, arg);
}
}
if (complain & tf_error)
- error ("%s", errstring);
+ error_at (location, "%s", errstring);
return error_mark_node;
}
if (type_unknown_p (rhs))
{
if (complain & tf_error)
- error ("no context to resolve type of %qE", rhs);
+ error_at (cp_expr_loc_or_input_loc (rhs),
+ "no context to resolve type of %qE", rhs);
return error_mark_node;
}
+2019-11-26 Paolo Carlini <paolo.carlini@oracle.com>
+
+ * g++.dg/cpp1z/bool-increment1.C: Test location(s) too.
+ * g++.dg/expr/bitfield3.C: Likewise.
+ * g++.dg/expr/bitfield4.C: Likewise.
+ * g++.dg/expr/bitfield5.C: Likewise.
+ * g++.dg/expr/bitfield6.C: Likewise.
+ * g++.dg/expr/bool1.C: Likewise.
+ * g++.dg/expr/bool2.C: Likewise.
+ * g++.dg/expr/bool3.C: Likewise.
+ * g++.dg/expr/bool4.C: Likewise.
+ * g++.dg/expr/lval3.C: Likewise.
+ * g++.dg/other/error18.C: Likewise.
+ * g++.dg/warn/Wpointer-arith-1.C: Likewise.
+ * g++.old-deja/g++.bugs/900212_01.C: Likewise.
+ * g++.old-deja/g++.bugs/900428_02.C: Likewise.
+ * g++.old-deja/g++.jason/rfg14.C: Likewise.
+ * g++.old-deja/g++.other/overload11.C: Likewise.
+
2019-11-26 Martin Sebor <msebor@redhat.com>
PR tree-optimization/92683
{
int r = 0;
- r += b++; // { dg-error "use of an operand of type .bool. in .operator\\+\\+. is forbidden in" }
- r += ++b; // { dg-error "use of an operand of type .bool. in .operator\\+\\+. is forbidden in" }
- r += b--; // { dg-error "use of an operand of type .bool. in .operator--. is forbidden" }
- r += --b; // { dg-error "use of an operand of type .bool. in .operator--. is forbidden" }
+ r += b++; // { dg-error "8:use of an operand of type .bool. in .operator\\+\\+. is forbidden in" }
+ r += ++b; // { dg-error "10:use of an operand of type .bool. in .operator\\+\\+. is forbidden in" }
+ r += b--; // { dg-error "8:use of an operand of type .bool. in .operator--. is forbidden" }
+ r += --b; // { dg-error "10:use of an operand of type .bool. in .operator--. is forbidden" }
return r;
}
S s;
void f() {
- s.x--; // { dg-error "use of an operand of type .bool." }
- --s.x; // { dg-error "use of an operand of type .bool." }
+ s.x--; // { dg-error "5:use of an operand of type .bool." }
+ --s.x; // { dg-error "7:use of an operand of type .bool." }
}
void f(bool) {}
int main() {
- f(s.x++); // { dg-warning "deprecated" "" { target { ! c++17 } } }
+ f(s.x++); // { dg-warning "7:use of an operand of type .bool. in .operator\\+\\+. is deprecated" "" { target { ! c++17 } } }
// { dg-error "forbidden" "" { target c++17 } .-1 }
- f(++s.x); // { dg-warning "deprecated" "" { target { ! c++17 } } }
+ f(++s.x); // { dg-warning "9:use of an operand of type .bool. in .operator\\+\\+. is deprecated" "" { target { ! c++17 } } }
// { dg-error "forbidden" "" { target c++17 } .-1 }
}
S s;
int main() {
- s.x++; // { dg-warning "deprecated" "" { target { ! c++17 } } }
+ s.x++; // { dg-warning "5:use of an operand of type .bool. in .operator\\+\\+. is deprecated" "" { target { ! c++17 } } }
// { dg-error "forbidden" "" { target c++17 } .-1 }
if (s.x != 1)
return 1;
- ++s.x; // { dg-warning "deprecated" "" { target { ! c++17 } } }
+ ++s.x; // { dg-warning "7:use of an operand of type .bool. in .operator\\+\\+. is deprecated" "" { target { ! c++17 } } }
// { dg-error "forbidden" "" { target c++17 } .-1 }
if (s.x != 1)
return 2;
S s;
void f() {
- ++s.x = false; // { dg-warning "deprecated" "" { target { ! c++17 } } }
+ ++s.x = false; // { dg-warning "7:use of an operand of type .bool. in .operator\\+\\+. is deprecated" "" { target { ! c++17 } } }
// { dg-error "forbidden" "" { target c++17 } .-1 }
}
my_bool b = false;
int i;
- b++; // { dg-warning "deprecated" "" { target { ! c++17 } } }
- // { dg-error "forbidden" "" { target c++17 } .-1 }
- b++; // { dg-warning "deprecated" "" { target { ! c++17 } } }
- // { dg-error "forbidden" "" { target c++17 } .-1 }
+ b++; // { dg-warning "3:use of an operand of type .bool. in .operator\\+\\+. is deprecated" "" { target { ! c++17 } } }
+ // { dg-error "3:use of an operand of type .bool. in .operator\\+\\+. is forbidden" "" { target c++17 } .-1 }
+ b++; // { dg-warning "3:use of an operand of type .bool. in .operator\\+\\+. is deprecated" "" { target { ! c++17 } } }
+ // { dg-error "3:use of an operand of type .bool. in .operator\\+\\+. is forbidden" "" { target c++17 } .-1 }
i = b;
if (i != 1)
abort ();
int main()
{
my_bool b = false;
- b--; // { dg-error "" }
+ b--; // { dg-error "3:use of an operand of type .bool. in .operator\\-\\-. is forbidden" }
return 0;
}
my_bool b = false;
int i;
- b++; // { dg-warning "deprecated" "" { target { ! c++17 } } }
- // { dg-error "forbidden" "" { target c++17 } .-1 }
+ b++; // { dg-warning "3:use of an operand of type .bool. in .operator\\+\\+. is deprecated" "" { target { ! c++17 } } }
+ // { dg-error "3:use of an operand of type .bool. in .operator\\+\\+. is forbidden" "" { target c++17 } .-1 }
// { dg-warning ".volatile.-qualified type is deprecated" "" { target c++2a } .-2 }
- b++; // { dg-warning "deprecated" "" { target { ! c++17 } } }
- // { dg-error "forbidden" "" { target c++17 } .-1 }
+ b++; // { dg-warning "3:use of an operand of type .bool. in .operator\\+\\+. is deprecated" "" { target { ! c++17 } } }
+ // { dg-error "3:use of an operand of type .bool. in .operator\\+\\+. is forbidden" "" { target c++17 } .-1 }
// { dg-warning ".volatile.-qualified type is deprecated" "" { target c++2a } .-2 }
i = b;
if (i != 1)
int main()
{
my_bool b = false;
- b--; // { dg-error "" }
+ b--; // { dg-error "3:use of an operand of type .bool. in .operator\\-\\-. is forbidden" }
// { dg-warning ".volatile.-qualified type is deprecated" "" { target c++2a } .-1 }
return 0;
}
{
bool i = 0;
i++ = 3; // { dg-error "" }
- // { dg-warning "deprecated" "" { target { ! c++17 } } .-1 }
+ // { dg-warning "3:use of an operand of type .bool. in .operator\\+\\+. is deprecated" "" { target { ! c++17 } } .-1 }
}
void f(A a)
{
- a.b--; // { dg-error "use of an operand of type .bool." }
+ a.b--; // { dg-error "5:use of an operand of type .bool." }
}
int main()
{
void *pv = 0;
- pv++; // { dg-warning "forbids incrementing a pointer" }
+ pv++; // { dg-warning "3:ISO C\\+\\+ forbids incrementing a pointer" }
typedef void (*pft) ();
pft pf = 0;
- pf++; // { dg-warning "forbids incrementing a pointer" }
+ pf++; // { dg-warning "3:ISO C\\+\\+ forbids incrementing a pointer" }
}
{
p0 = p1 + 3; // { dg-error "" }
p0 = p1 - 3; // { dg-error "" }
- p1++; /* { dg-error "" } caught by g++ */
- ++p1; /* { dg-error "" } caught by g++ */
- p1--; /* { dg-error "" } caught by g++ */
- --p1; /* { dg-error "" } caught by g++ */
+ p1++; /* { dg-error "3:no post-increment" } caught by g++ */
+ ++p1; /* { dg-error "5:no pre-increment" } caught by g++ */
+ p1--; /* { dg-error "3:no post-decrement" } caught by g++ */
+ --p1; /* { dg-error "5:no pre-decrement" } caught by g++ */
fp0 = fp1 + 3; // { dg-error "" }
fp0 = fp1 - 3; // { dg-error "" }
- fp1++; /* { dg-error "" } */
- ++fp1; /* { dg-error "" } */
- fp1--; /* { dg-error "" } */
- --fp1; /* { dg-error "" } */
+ fp1++; /* { dg-error "3:no post-increment" } */
+ ++fp1; /* { dg-error "5:no pre-increment" } */
+ fp1--; /* { dg-error "3:no post-decrement" } */
+ --fp1; /* { dg-error "5:no pre-decrement" } */
}
int main () { return 0; }
void test ()
{
- vp++; /* { dg-error "" } */
- ++vp; /* { dg-error "" } */
- vp--; /* { dg-error "" } */
- --vp; /* { dg-error "" } */
+ vp++; /* { dg-error "3:ISO C\\+\\+ forbids incrementing" } */
+ ++vp; /* { dg-error "5:ISO C\\+\\+ forbids incrementing" } */
+ vp--; /* { dg-error "3:ISO C\\+\\+ forbids decrementing" } */
+ --vp; /* { dg-error "5:ISO C\\+\\+ forbids decrementing" } */
- fp++; /* { dg-error "" } */
- ++fp; /* { dg-error "" } */
- fp--; /* { dg-error "" } */
- --fp; /* { dg-error "" } */
+ fp++; /* { dg-error "3:ISO C\\+\\+ forbids incrementing" } */
+ ++fp; /* { dg-error "5:ISO C\\+\\+ forbids incrementing" } */
+ fp--; /* { dg-error "3:ISO C\\+\\+ forbids decrementing" } */
+ --fp; /* { dg-error "5:ISO C\\+\\+ forbids decrementing" } */
}
void
test ()
{
- vp++; /* { dg-error "" } incrementing void * */
- ap++; /* { dg-error "" } incrementing ptr to incomplete type */
- sp++; /* { dg-error "" } incrementing ptr to incomplete type */
- up++; /* { dg-error "" } incrementing ptr to incomplete type */
- fp++; /* { dg-error "" } incrementing ptr to function */
+ vp++; /* { dg-error "5:ISO C\\+\\+ forbids incrementing" } incrementing void * */
+ ap++; /* { dg-error "5:cannot increment" } incrementing ptr to incomplete type */
+ sp++; /* { dg-error "5:cannot increment" } incrementing ptr to incomplete type */
+ up++; /* { dg-error "5:cannot increment" } incrementing ptr to incomplete type */
+ fp++; /* { dg-error "5:ISO C\\+\\+ forbids incrementing" } incrementing ptr to function */
}
// 13.3.1.1 indicates that the following are errors -- the primary expression
// is not the name of a function.
- (0, ovl) (1); // { dg-error "" } not suitable for overload resolution
- (0, &ovl) (1); // { dg-error "" } not suitable for overload resolution
+ (0, ovl) (1); // { dg-error "7:no context" } not suitable for overload resolution
+ (0, &ovl) (1); // { dg-error "7:no context" } not suitable for overload resolution
(argc ? ovl : ovl) (1); // { dg-error "" } not suitable for overload resolution
(argc ? &ovl : &ovl) (1); // { dg-error "" } not suitable for overload resolution
ptr = (ovl); // ok
ptr = (&ovl); // ok
- ptr = (0, ovl); // ok { dg-error "no context" }
- ptr = (0, &ovl); // ok { dg-error "no context" }
+ ptr = (0, ovl); // ok { dg-error "13:no context" }
+ ptr = (0, &ovl); // ok { dg-error "13:no context" }
ptr = (argc ? ovl : ovl); // ok { dg-error "no context" }
ptr = (argc ? &ovl : &ovl);// ok { dg-error "no context" }
vptr = (ovl); // { dg-error "" } no matching candidates
vptr = (&ovl); // { dg-error "" } no matching candidates
- vptr = (0, ovl); // { dg-error "" } no matching candidates
- vptr = (0, &ovl); // { dg-error "" } no matching candidates
+ vptr = (0, ovl); // { dg-error "14:no context" } no matching candidates
+ vptr = (0, &ovl); // { dg-error "14:no context" } no matching candidates
vptr = (argc ? ovl : ovl); // { dg-error "" } no matching candidates
vptr = (argc ? &ovl : &ovl);// { dg-error "" } no matching candidates
static_cast<void>(ovl); // { dg-error "" } not suitable for overload
static_cast<void>(&ovl); // { dg-error "" } not suitable for overload
((void)1, f); // { dg-warning "" "" { xfail *-*-* } } not a call
- ((void)1, ovl); // { dg-error "" } not suitable for overload
- ((void)1, &ovl); // { dg-error "" } not suitable for overload
+ ((void)1, ovl); // { dg-error "13:no context" } not suitable for overload
+ ((void)1, &ovl); // { dg-error "13:no context" } not suitable for overload
(void)((void)1, f); // ok
- (void)((void)1, ovl); // { dg-error "" } not suitable for overload
- (void)((void)1, &ovl); // { dg-error "" } not suitable for overload
+ (void)((void)1, ovl); // { dg-error "19:no context" } not suitable for overload
+ (void)((void)1, &ovl); // { dg-error "19:no context" } not suitable for overload
return 0;
}