+2019-12-18 Paolo Carlini <paolo.carlini@oracle.com>
+
+ * typeck.c (cxx_sizeof_or_alignof_type): Add location_t parameter
+ and use it throughout.
+ (cxx_sizeof_expr): Likewise.
+ (cxx_alignof_expr): Likewise.
+ (cxx_sizeof_or_alignof_expr): Likewise.
+ (cxx_alignas_expr): Update call.
+ * decl.c (fold_sizeof_expr): Likewise.
+ * pt.c (tsubst_copy): Likewise.
+ (tsubst_copy_and_build): Likewise.
+ * except.c (build_throw): Add location_t parameter and use it.
+ (expand_end_catch_block): Update call.
+ * parser.c (cp_parser_unary_expression): Update
+ cxx_sizeof_or_alignof_type and cxx_sizeof_or_alignof_expr calls,
+ pass the compound location.
+ (cp_parser_throw_expression): Likewise pass the combined location
+ to build_throw.
+ * cp-tree.h: Update declarations.
+
+ * semantics.c (finish_handler_parms): Use DECL_SOURCE_LOCATION.
+ * decl2.c (check_classfn): Likewise.
+
+ * except.c (is_admissible_throw_operand_or_catch_parameter):
+ Exploit cp_expr_loc_or_input_loc in one place.
+
+ * except.c (create_try_catch_expr): Remove, unused.
+
2019-12-17 Jason Merrill <jason@redhat.com>
PR c++/12333 - X::~X() with implicit this->.
extern tree expand_start_catch_block (tree);
extern void expand_end_catch_block (void);
extern tree build_exc_ptr (void);
-extern tree build_throw (tree);
+extern tree build_throw (location_t, tree);
extern int nothrow_libfn_p (const_tree);
extern void check_handlers (tree);
extern tree finish_noexcept_expr (tree, tsubst_flags_t);
extern void finish_eh_spec_block (tree, tree);
extern tree build_eh_type_type (tree);
extern tree cp_protect_cleanup_actions (void);
-extern tree create_try_catch_expr (tree, tree);
extern tree template_parms_to_args (tree);
extern tree template_parms_level_to_args (tree);
extern tree generic_targs_for (tree);
extern int comp_cv_qualification (const_tree, const_tree);
extern int comp_cv_qualification (int, int);
extern int comp_cv_qual_signature (tree, tree);
-extern tree cxx_sizeof_or_alignof_expr (tree, enum tree_code, bool);
-extern tree cxx_sizeof_or_alignof_type (tree, enum tree_code, bool, bool);
+extern tree cxx_sizeof_or_alignof_expr (location_t, tree,
+ enum tree_code, bool);
+extern tree cxx_sizeof_or_alignof_type (location_t, tree,
+ enum tree_code, bool, bool);
extern tree cxx_alignas_expr (tree);
extern tree cxx_sizeof_nowarn (tree);
extern tree is_bitfield_expr_with_lowered_type (const_tree);
extern tree build_x_vec_perm_expr (location_t,
tree, tree, tree,
tsubst_flags_t);
-#define cxx_sizeof(T) cxx_sizeof_or_alignof_type (T, SIZEOF_EXPR, false, true)
+#define cxx_sizeof(T) cxx_sizeof_or_alignof_type (input_location, T, SIZEOF_EXPR, false, true)
extern tree build_simple_component_ref (tree, tree);
extern tree build_ptrmemfunc_access_expr (tree, tree);
extern tree build_address (tree);
{
tree r;
if (SIZEOF_EXPR_TYPE_P (t))
- r = cxx_sizeof_or_alignof_type (TREE_TYPE (TREE_OPERAND (t, 0)),
+ r = cxx_sizeof_or_alignof_type (EXPR_LOCATION (t),
+ TREE_TYPE (TREE_OPERAND (t, 0)),
SIZEOF_EXPR, false, false);
else if (TYPE_P (TREE_OPERAND (t, 0)))
- r = cxx_sizeof_or_alignof_type (TREE_OPERAND (t, 0), SIZEOF_EXPR,
+ r = cxx_sizeof_or_alignof_type (EXPR_LOCATION (t),
+ TREE_OPERAND (t, 0), SIZEOF_EXPR,
false, false);
else
- r = cxx_sizeof_or_alignof_expr (TREE_OPERAND (t, 0), SIZEOF_EXPR,
+ r = cxx_sizeof_or_alignof_expr (EXPR_LOCATION (t),
+ TREE_OPERAND (t, 0), SIZEOF_EXPR,
false);
if (r == error_mark_node)
r = size_one_node;
if (!matched)
{
if (!COMPLETE_TYPE_P (ctype))
- cxx_incomplete_type_error (function, ctype);
+ cxx_incomplete_type_error (DECL_SOURCE_LOCATION (function),
+ function, ctype);
else
{
if (DECL_CONV_FN_P (function))
&& (DECL_CONSTRUCTOR_P (current_function_decl)
|| DECL_DESTRUCTOR_P (current_function_decl)))
{
- tree rethrow = build_throw (NULL_TREE);
+ tree rethrow = build_throw (input_location, NULL_TREE);
TREE_NO_WARNING (rethrow) = true;
finish_expr_stmt (rethrow);
}
/* Build a throw expression. */
tree
-build_throw (tree exp)
+build_throw (location_t loc, tree exp)
{
if (exp == error_mark_node)
return exp;
if (cfun)
current_function_returns_abnormally = 1;
exp = build_min (THROW_EXPR, void_type_node, exp);
- SET_EXPR_LOCATION (exp, input_location);
+ SET_EXPR_LOCATION (exp, loc);
return exp;
}
if (exp && null_node_p (exp))
- warning (0, "throwing NULL, which has integral, not pointer type");
+ warning_at (loc, 0,
+ "throwing NULL, which has integral, not pointer type");
if (exp != NULL_TREE)
{
{
int flags = LOOKUP_NORMAL | LOOKUP_ONLYCONVERTING;
bool converted = false;
+ location_t exp_loc = cp_expr_loc_or_loc (exp, loc);
/* Under C++0x [12.8/16 class.copy], a thrown lvalue is sometimes
treated as an rvalue for the purposes of overload resolution
if (exp == error_mark_node)
{
- error (" in thrown expression");
+ inform (exp_loc, " in thrown expression");
return error_mark_node;
}
}
exp = cp_build_function_call_vec (rethrow_fn, NULL, tf_warning_or_error);
}
- exp = build1 (THROW_EXPR, void_type_node, exp);
- SET_EXPR_LOCATION (exp, input_location);
+ exp = build1_loc (loc, THROW_EXPR, void_type_node, exp);
return exp;
}
else if (variably_modified_type_p (type, NULL_TREE))
{
if (is_throw)
- error ("cannot throw expression of type %qT because it involves "
- "types of variable size", type);
+ error_at (cp_expr_loc_or_input_loc (expr),
+ "cannot throw expression of type %qT because it involves "
+ "types of variable size", type);
else
error ("cannot catch type %qT because it involves types of "
"variable size", type);
}
}
-/* Returns a TRY_CATCH_EXPR that will put TRY_LIST and CATCH_LIST in the
- TRY and CATCH locations. CATCH_LIST must be a STATEMENT_LIST */
-
-tree
-create_try_catch_expr (tree try_expr, tree catch_list)
-{
- location_t loc = EXPR_LOCATION (try_expr);
-
- append_to_statement_list (do_begin_catch (), &catch_list);
- append_to_statement_list (build_throw (NULL_TREE), &catch_list);
- tree catch_tf_expr = build_stmt (loc, TRY_FINALLY_EXPR, catch_list,
- do_end_catch (NULL_TREE));
- catch_list = build2 (CATCH_EXPR, void_type_node, NULL_TREE,
- catch_tf_expr);
- tree try_catch_expr = build_stmt (loc, TRY_CATCH_EXPR, try_expr, catch_list);
- return try_catch_expr;
-}
-
#include "gt-cp-except.h"
/* Parse the operand. */
operand = cp_parser_sizeof_operand (parser, keyword);
+ /* Construct a location e.g. :
+ alignof (expr)
+ ^~~~~~~~~~~~~~
+ with start == caret at the start of the "alignof"/"sizeof"
+ token, with the endpoint at the final closing paren. */
+ location_t compound_loc
+ = make_location (start_loc, start_loc, parser->lexer);
+
if (TYPE_P (operand))
- ret = cxx_sizeof_or_alignof_type (operand, op, std_alignof,
- true);
+ ret = cxx_sizeof_or_alignof_type (compound_loc, operand, op,
+ std_alignof, true);
else
{
/* ISO C++ defines alignof only with types, not with
"ISO C++ does not allow %<alignof%> "
"with a non-type");
- ret = cxx_sizeof_or_alignof_expr (operand, op, true);
+ ret = cxx_sizeof_or_alignof_expr (compound_loc,
+ operand, op, true);
}
/* For SIZEOF_EXPR, just issue diagnostics, but keep
SIZEOF_EXPR with the original operand. */
ret = build_min (SIZEOF_EXPR, size_type_node, operand);
TREE_SIDE_EFFECTS (ret) = 0;
TREE_READONLY (ret) = 1;
+ SET_EXPR_LOCATION (ret, compound_loc);
}
}
- /* Construct a location e.g. :
- alignof (expr)
- ^~~~~~~~~~~~~~
- with start == caret at the start of the "alignof"/"sizeof"
- token, with the endpoint at the final closing paren. */
- location_t compound_loc
- = make_location (start_loc, start_loc, parser->lexer);
-
- cp_expr ret_expr (ret);
- ret_expr.set_location (compound_loc);
+ cp_expr ret_expr (ret, compound_loc);
ret_expr = ret_expr.maybe_add_location_wrapper ();
return ret_expr;
}
the end at the end of the final token we consumed. */
location_t combined_loc = make_location (start_loc, start_loc,
parser->lexer);
- expression = build_throw (expression);
- protected_set_expr_location (expression, combined_loc);
+ expression = build_throw (combined_loc, expression);
return expression;
}
expanded = make_argument_pack (expanded);
if (TYPE_P (expanded))
- return cxx_sizeof_or_alignof_type (expanded, SIZEOF_EXPR,
+ return cxx_sizeof_or_alignof_type (input_location,
+ expanded, SIZEOF_EXPR,
false,
complain & tf_error);
else
- return cxx_sizeof_or_alignof_expr (expanded, SIZEOF_EXPR,
+ return cxx_sizeof_or_alignof_expr (input_location,
+ expanded, SIZEOF_EXPR,
complain & tf_error);
}
else
--c_inhibit_evaluation_warnings;
}
if (TYPE_P (op1))
- r = cxx_sizeof_or_alignof_type (op1, TREE_CODE (t), std_alignof,
+ r = cxx_sizeof_or_alignof_type (input_location,
+ op1, TREE_CODE (t), std_alignof,
complain & tf_error);
else
- r = cxx_sizeof_or_alignof_expr (op1, TREE_CODE (t),
+ r = cxx_sizeof_or_alignof_expr (input_location,
+ op1, TREE_CODE (t),
complain & tf_error);
if (TREE_CODE (t) == SIZEOF_EXPR && r != error_mark_node)
{
case THROW_EXPR:
RETURN (build_throw
- (RECUR (TREE_OPERAND (t, 0))));
+ (input_location, RECUR (TREE_OPERAND (t, 0))));
case CONSTRUCTOR:
{
if (CLASS_TYPE_P (orig_type))
{
if (TYPE_POLYMORPHIC_P (orig_type))
- warning (OPT_Wcatch_value_,
- "catching polymorphic type %q#T by value", orig_type);
+ warning_at (DECL_SOURCE_LOCATION (decl),
+ OPT_Wcatch_value_,
+ "catching polymorphic type %q#T by value",
+ orig_type);
else if (warn_catch_value > 1)
- warning (OPT_Wcatch_value_,
- "catching type %q#T by value", orig_type);
+ warning_at (DECL_SOURCE_LOCATION (decl),
+ OPT_Wcatch_value_,
+ "catching type %q#T by value", orig_type);
}
else if (warn_catch_value > 2)
- warning (OPT_Wcatch_value_,
- "catching non-reference type %q#T", orig_type);
+ warning_at (DECL_SOURCE_LOCATION (decl),
+ OPT_Wcatch_value_,
+ "catching non-reference type %q#T", orig_type);
}
}
HANDLER_TYPE (handler) = type;
SIZEOF_EXPR. */
tree
-cxx_sizeof_or_alignof_type (tree type, enum tree_code op, bool std_alignof,
- bool complain)
+cxx_sizeof_or_alignof_type (location_t loc, tree type, enum tree_code op,
+ bool std_alignof, bool complain)
{
gcc_assert (op == SIZEOF_EXPR || op == ALIGNOF_EXPR);
if (type == error_mark_node)
{
if (complain)
{
- pedwarn (input_location, OPT_Wpointer_arith,
+ pedwarn (loc, OPT_Wpointer_arith,
"invalid application of %qs to a member function",
OVL_OP_INFO (false, op)->name);
return size_one_node;
TREE_READONLY (value) = 1;
if (op == ALIGNOF_EXPR && std_alignof)
ALIGNOF_EXPR_STD_P (value) = true;
+ SET_EXPR_LOCATION (value, loc);
return value;
}
- return c_sizeof_or_alignof_type (input_location, complete_type (type),
+ return c_sizeof_or_alignof_type (loc, complete_type (type),
op == SIZEOF_EXPR, std_alignof,
complain);
}
else if (!COMPLETE_TYPE_P (type))
return size_zero_node;
else
- return cxx_sizeof_or_alignof_type (type, SIZEOF_EXPR, false, false);
+ return cxx_sizeof_or_alignof_type (input_location, type,
+ SIZEOF_EXPR, false, false);
}
/* Process a sizeof expression where the operand is an expression. */
static tree
-cxx_sizeof_expr (tree e, tsubst_flags_t complain)
+cxx_sizeof_expr (location_t loc, tree e, tsubst_flags_t complain)
{
if (e == error_mark_node)
return error_mark_node;
e = build_min (SIZEOF_EXPR, size_type_node, e);
TREE_SIDE_EFFECTS (e) = 0;
TREE_READONLY (e) = 1;
+ SET_EXPR_LOCATION (e, loc);
return e;
}
+ location_t e_loc = cp_expr_loc_or_loc (e, loc);
STRIP_ANY_LOCATION_WRAPPER (e);
/* To get the size of a static data member declared as an array of
&& (complain & tf_warning))
{
auto_diagnostic_group d;
- if (warning (OPT_Wsizeof_array_argument, "%<sizeof%> on array function "
- "parameter %qE will return size of %qT", e, TREE_TYPE (e)))
+ if (warning_at (e_loc, OPT_Wsizeof_array_argument,
+ "%<sizeof%> on array function parameter %qE "
+ "will return size of %qT", e, TREE_TYPE (e)))
inform (DECL_SOURCE_LOCATION (e), "declared here");
}
if (bitfield_p (e))
{
if (complain & tf_error)
- error_at (cp_expr_loc_or_input_loc (e),
+ error_at (e_loc,
"invalid application of %<sizeof%> to a bit-field");
else
return error_mark_node;
else if (is_overloaded_fn (e))
{
if (complain & tf_error)
- permerror (cp_expr_loc_or_input_loc (e),
- "ISO C++ forbids applying %<sizeof%> to an expression "
- "of function type");
+ permerror (e_loc, "ISO C++ forbids applying %<sizeof%> to "
+ "an expression of function type");
else
return error_mark_node;
e = char_type_node;
else if (type_unknown_p (e))
{
if (complain & tf_error)
- cxx_incomplete_type_error (e, TREE_TYPE (e));
+ cxx_incomplete_type_error (e_loc, e, TREE_TYPE (e));
else
return error_mark_node;
e = char_type_node;
else
e = TREE_TYPE (e);
- return cxx_sizeof_or_alignof_type (e, SIZEOF_EXPR, false, complain & tf_error);
+ return cxx_sizeof_or_alignof_type (loc, e, SIZEOF_EXPR, false,
+ complain & tf_error);
}
/* Implement the __alignof keyword: Return the minimum required
"aligned" __attribute__ specification). */
static tree
-cxx_alignof_expr (tree e, tsubst_flags_t complain)
+cxx_alignof_expr (location_t loc, tree e, tsubst_flags_t complain)
{
tree t;
e = build_min (ALIGNOF_EXPR, size_type_node, e);
TREE_SIDE_EFFECTS (e) = 0;
TREE_READONLY (e) = 1;
+ SET_EXPR_LOCATION (e, loc);
return e;
}
+ location_t e_loc = cp_expr_loc_or_loc (e, loc);
STRIP_ANY_LOCATION_WRAPPER (e);
e = mark_type_use (e);
- if (!verify_type_context (input_location, TCTX_ALIGNOF, TREE_TYPE (e),
+ if (!verify_type_context (loc, TCTX_ALIGNOF, TREE_TYPE (e),
!(complain & tf_error)))
{
if (!(complain & tf_error))
else if (bitfield_p (e))
{
if (complain & tf_error)
- error_at (cp_expr_loc_or_input_loc (e),
+ error_at (e_loc,
"invalid application of %<__alignof%> to a bit-field");
else
return error_mark_node;
else if (is_overloaded_fn (e))
{
if (complain & tf_error)
- permerror (cp_expr_loc_or_input_loc (e),
- "ISO C++ forbids applying %<__alignof%> to an expression "
- "of function type");
+ permerror (e_loc, "ISO C++ forbids applying %<__alignof%> to "
+ "an expression of function type");
else
return error_mark_node;
if (TREE_CODE (e) == FUNCTION_DECL)
else if (type_unknown_p (e))
{
if (complain & tf_error)
- cxx_incomplete_type_error (e, TREE_TYPE (e));
+ cxx_incomplete_type_error (e_loc, e, TREE_TYPE (e));
else
return error_mark_node;
t = size_one_node;
}
else
- return cxx_sizeof_or_alignof_type (TREE_TYPE (e), ALIGNOF_EXPR, false,
+ return cxx_sizeof_or_alignof_type (loc, TREE_TYPE (e),
+ ALIGNOF_EXPR, false,
complain & tf_error);
- return fold_convert (size_type_node, t);
+ return fold_convert_loc (loc, size_type_node, t);
}
/* Process a sizeof or alignof expression E with code OP where the operand
is an expression. */
tree
-cxx_sizeof_or_alignof_expr (tree e, enum tree_code op, bool complain)
+cxx_sizeof_or_alignof_expr (location_t loc, tree e, enum tree_code op,
+ bool complain)
{
if (op == SIZEOF_EXPR)
- return cxx_sizeof_expr (e, complain? tf_warning_or_error : tf_none);
+ return cxx_sizeof_expr (loc, e, complain? tf_warning_or_error : tf_none);
else
- return cxx_alignof_expr (e, complain? tf_warning_or_error : tf_none);
+ return cxx_alignof_expr (loc, e, complain? tf_warning_or_error : tf_none);
}
/* Build a representation of an expression 'alignas(E).' Return the
alignas(type-id ), it shall have the same effect as
alignas(alignof(type-id )). */
- return cxx_sizeof_or_alignof_type (e, ALIGNOF_EXPR, true, false);
+ return cxx_sizeof_or_alignof_type (input_location,
+ e, ALIGNOF_EXPR, true, false);
/* If we reach this point, it means the alignas expression if of
the form "alignas(assignment-expression)", so we should follow
+2019-12-18 Paolo Carlini <paolo.carlini@oracle.com>
+
+ * g++.dg/diagnostic/alignof2.C: New.
+ * g++.dg/diagnostic/alignof3.C: Likewise.
+ * g++.dg/diagnostic/incomplete-type-1.C: Likewise.
+ * g++.dg/warn/Wcatch-value-3b.C: Likewise.
+ * g++.dg/cpp0x/alignof3.C: Check location(s) too.
+ * g++.dg/cpp1z/decomp-bitfield1.C: Likewise.
+ * g++.dg/cpp1z/has-unique-obj-representations2.C: Likewise.
+ * g++.dg/expr/sizeof3.C: Likewise.
+ * g++.dg/ext/flexary6.C: Likewise.
+ * g++.dg/ext/vla4.C: Likewise.
+ * g++.dg/template/sizeof11.C: Likewise.
+ * g++.dg/warn/Wcatch-value-1.C: Likewise.
+ * g++.dg/warn/Wcatch-value-2.C: Likewise.
+ * g++.dg/warn/Wcatch-value-3.C: Likewise.
+ * g++.old-deja/g++.brendan/sizeof1.C: Likewise.
+ * g++.old-deja/g++.brendan/sizeof3.C: Likewise.
+ * g++.old-deja/g++.brendan/sizeof4.C: Likewise.
+ * g++.old-deja/g++.eh/ctor1.C: Likewise.
+ * g++.old-deja/g++.jason/ambig1.C: Likewise.
+ * g++.old-deja/g++.other/sizeof4.C: Likewise.
+
2019-12-18 Peter Bergner <bergner@linux.ibm.com>
PR bootstrap/92661
// { dg-options "-pedantic" }
int main(void)
{
- alignof(void (void)); // { dg-warning "function type" }
+ alignof(void (void)); // { dg-warning "3:ISO C\\+\\+ does not permit .alignof. applied to a function type" }
}
long &r = x; // { dg-error "bit" }
&x; // { dg-error "bit" }
- sizeof(x); // { dg-error "bit" }
+ sizeof(x); // { dg-error "10:invalid application of .sizeof. to a bit-field" }
}
struct S;
-struct T { S t; }; // { dg-error "incomplete type" }
-struct U { int u[sizeof (S)]; }; // { dg-error "incomplete type" }
+struct T { S t; }; // { dg-error "14:field .t. has incomplete type" }
+struct U { int u[sizeof (S)]; }; // { dg-error "18:invalid application of .sizeof. to incomplete type" }
union V { char c; char d[]; }; // { dg-error "24:flexible array member in union" }
bool a = __has_unique_object_representations (S); // { dg-error "incomplete type" }
bool b = __has_unique_object_representations (T);
--- /dev/null
+void f();
+int i = __alignof(f); // { dg-error "19:ISO C\\+\\+ forbids applying .__alignof." }
--- /dev/null
+struct A { long i: 2; };
+void f()
+{
+ __alignof(A::i); // { dg-error "16:invalid application of .__alignof. to a bit-field" }
+}
--- /dev/null
+template<typename> struct A; // { dg-message "27:declaration" }
+template<typename T> A<T>::A(); // { dg-error "22:invalid use of incomplete type" }
// PR c++/15337
class CCC;
-int main() { sizeof(CCC); return 0; } // { dg-error ".*CCC.*" }
+int main() { sizeof(CCC); return 0; } // { dg-error "14:invalid application of .sizeof. to incomplete type .CCC." }
int n;
int a[];
enum {
- e = sizeof a // { dg-error "invalid application of .sizeof. to incomplete type" }
+ e = sizeof a // { dg-error "9:invalid application of .sizeof. to incomplete type" }
};
};
typedef int A[];
A a;
enum {
- e = sizeof a // { dg-error "invalid application of .sizeof. to incomplete type" }
+ e = sizeof a // { dg-error "9:invalid application of .sizeof. to incomplete type" }
};
};
void f(int i) {
try {
int a[i];
- throw &a; // { dg-error "int \\(\\*\\)\\\[i\\\]" }
+ throw &a; // { dg-error "11:cannot throw expression of type .int \\(\\*\\)\\\[i\\\]." }
} catch (int (*)[i]) { // { dg-error "variable size" }
}
}
template < class T > struct B;
template < int> void f()
{
- sizeof (B<int>); // { dg-error "incomplete" }
+ sizeof (B<int>); // { dg-error "3:invalid application of .sizeof. to incomplete type" }
}
try {}
catch (D) {}
catch (C) {}
- catch (B) {} // { dg-warning "catching polymorphic type" }
- catch (A) {} // { dg-warning "catching polymorphic type" }
+ catch (B) {} // { dg-warning "10:catching polymorphic type" }
+ catch (A) {} // { dg-warning "10:catching polymorphic type" }
catch (A*) {}
catch (int) {}
template<typename T> void foo1()
{
try {}
- catch (T) {} // { dg-warning "catching polymorphic type" }
+ catch (T) {} // { dg-warning "10:catching polymorphic type" }
}
template<typename T> void foo2()
void foo()
{
try {}
- catch (D) {} // { dg-warning "catching type" }
- catch (C) {} // { dg-warning "catching type" }
- catch (B) {} // { dg-warning "catching polymorphic type" }
- catch (A) {} // { dg-warning "catching polymorphic type" }
+ catch (D) {} // { dg-warning "10:catching type" }
+ catch (C) {} // { dg-warning "10:catching type" }
+ catch (B) {} // { dg-warning "10:catching polymorphic type" }
+ catch (A) {} // { dg-warning "10:catching polymorphic type" }
catch (A*) {}
catch (int) {}
template<typename T> void foo1()
{
try {}
- catch (T) {} // { dg-warning "catching" }
+ catch (T) {} // { dg-warning "10:catching" }
}
template<typename T> void foo2()
void foo()
{
try {}
- catch (D) {} // { dg-warning "catching type" }
- catch (C) {} // { dg-warning "catching type" }
- catch (B) {} // { dg-warning "catching polymorphic type" }
- catch (A) {} // { dg-warning "catching polymorphic type" }
+ catch (D) {} // { dg-warning "10:catching type" }
+ catch (C) {} // { dg-warning "10:catching type" }
+ catch (B) {} // { dg-warning "10:catching polymorphic type" }
+ catch (A) {} // { dg-warning "10:catching polymorphic type" }
catch (A*) {} // { dg-warning "catching non-reference type" }
- catch (int) {} // { dg-warning "catching non-reference type" }
+ catch (int) {} // { dg-warning "10:catching non-reference type" }
try {}
catch (D&) {}
template<typename T> void foo1()
{
try {}
- catch (T) {} // { dg-warning "catching" }
+ catch (T) {} // { dg-warning "10:catching" }
}
template<typename T> void foo2()
--- /dev/null
+// { dg-options "-Wcatch-value=3" }
+
+struct A { virtual ~A() {} };
+struct B : A {};
+struct C {};
+struct D : C {};
+
+void foo()
+{
+ try {}
+ catch (D d) {} // { dg-warning "12:catching type" }
+ catch (C c) {} // { dg-warning "12:catching type" }
+ catch (B b) {} // { dg-warning "12:catching polymorphic type" }
+ catch (A a) {} // { dg-warning "12:catching polymorphic type" }
+ catch (A* a) {} // { dg-warning "13:catching non-reference type" }
+ catch (int i) {} // { dg-warning "14:catching non-reference type" }
+
+ try {}
+ catch (D& d) {}
+ catch (C& c) {}
+ catch (B& b) {}
+ catch (A& a) {}
+ catch (A* a) {} // { dg-warning "13:catching non-reference type" }
+ catch (int& i) {}
+}
+
+template<typename T> void foo1()
+{
+ try {}
+ catch (T t) {} // { dg-warning "12:catching" }
+}
+
+template<typename T> void foo2()
+{
+ try {}
+ catch (T* t) {} // { dg-warning "13:catching non-reference type" }
+
+ try {}
+ catch (T&) {}
+
+ try {}
+ catch (const T&) {}
+}
+
+void bar()
+{
+ foo1<int&>();
+ foo1<const A&>();
+ foo1<B&>();
+ foo1<const C&>();
+ foo1<D&>();
+
+ foo1<int>(); // { dg-message "required" }
+ foo1<A>(); // { dg-message "required" }
+ foo1<B>(); // { dg-message "required" }
+ foo1<C>(); // { dg-message "required" }
+ foo1<D>(); // { dg-message "required" }
+
+ foo2<int>(); // { dg-message "required" }
+ foo2<A>(); // { dg-message "required" }
+ foo2<B>(); // { dg-message "required" }
+ foo2<C>(); // { dg-message "required" }
+ foo2<D>(); // { dg-message "required" }
+}
main()
{
// sizeof may not be applied to a function
- int i = sizeof( f);// { dg-error "" } .*
+ int i = sizeof( f);// { dg-error "19:ISO C\\+\\+ forbids applying .sizeof." } .*
return 0;
}
main()
{
// sizeof may not be applied to an undefined class
- int k = sizeof (bar);// { dg-error "" } .*
+ int k = sizeof (bar);// { dg-error "11:invalid application of .sizeof. to incomplete type" } .*
return 0;
}
main()
{
// sizeof may not be applied to the type void
- int l = sizeof (void);// { dg-error "" } .*
+ int l = sizeof (void);// { dg-error "11:invalid application of .sizeof. to a void type" } .*
return 0;
}
try
{
throw A(); // { dg-error "rvalue" "" { target c++14_down } } can't copy
- // { dg-error "thrown expression" "expr" { target c++14_down } .-1 }
+ // { dg-message "13:thrown expression" "expr" { target c++14_down } .-1 }
}
catch (...) { }
}
// Testcase for ambiguity between functional cast and abstract declarator.
// This ambiguity accounts for 6 of the r/r conflicts.
-int i = sizeof (int ()); // { dg-error "" } sizeof applied to fn type
+int i = sizeof (int ()); // { dg-error "9:invalid application of .sizeof. to a function type" } sizeof applied to fn type
int j = sizeof (int () + 1);
int main (int argc, char **argv)
{
- sizeof (s); // { dg-error "" } incomplete
- sizeof (0, s); // { dg-error "" } incomplete
- sizeof (argc ? s : s); // { dg-error "" } incomplete
+ sizeof (s); // { dg-error "3:invalid application of .sizeof. to incomplete type" } incomplete
+ sizeof (0, s); // { dg-error "3:invalid application of .sizeof. to incomplete type" } incomplete
+ sizeof (argc ? s : s); // { dg-error "3:invalid application of .sizeof. to incomplete type" } incomplete
- sizeof (arys); // { dg-error "" } incomplete
- sizeof (0, arys); // { dg-error "" } incomplete
- sizeof (argc ? arys : arys); // { dg-error "" } incomplete
+ sizeof (arys); // { dg-error "3:invalid application of .sizeof. to incomplete type" } incomplete
+ sizeof (0, arys); // { dg-error "3:invalid application of .sizeof. to incomplete type" } incomplete
+ sizeof (argc ? arys : arys); // { dg-error "3:invalid application of .sizeof. to incomplete type" } incomplete
- sizeof (aryt); // { dg-error "" } incomplete
- sizeof (0, aryt); // { dg-error "" } incomplete
- sizeof (argc ? aryt : aryt); // { dg-error "" } incomplete
+ sizeof (aryt); // { dg-error "3:invalid application of .sizeof. to incomplete type" } incomplete
+ sizeof (0, aryt); // { dg-error "3:invalid application of .sizeof. to incomplete type" } incomplete
+ sizeof (argc ? aryt : aryt); // { dg-error "3:invalid application of .sizeof. to incomplete type" } incomplete
- sizeof (fn); // { dg-error "" } cannot take size of function
- sizeof (0, fn); // { dg-error "" } cannot take size of function
- sizeof (argc ? fn : fn); // { dg-error "" } cannot take size of function
+ sizeof (fn); // { dg-error "11:ISO C\\+\\+ forbids applying .sizeof." } cannot take size of function
+ sizeof (0, fn); // { dg-error "3:invalid application of .sizeof. to a function type" } cannot take size of function
+ sizeof (argc ? fn : fn); // { dg-error "3:invalid application of .sizeof. to a function type" } cannot take size of function
sizeof (&fn); // ok
sizeof (0, &fn); // ok
+2019-12-18 Paolo Carlini <paolo.carlini@oracle.com>
+
+ * libcp1plugin.cc (plugin_build_unary_expr): Update build_throw
+ and cxx_sizeof_or_alignof_expr calls.
+ (plugin_build_unary_type_expr): Likewise for
+ cxx_sizeof_or_alignof_type.
+
2019-12-09 Paolo Carlini <paolo.carlini@oracle.com>
* libcp1plugin.cc (plugin_build_cast_expr): Adjust build_cast
break;
case THROW_EXPR:
- result = build_throw (op0);
+ result = build_throw (input_location, op0);
break;
case TYPEID_EXPR:
case SIZEOF_EXPR:
case ALIGNOF_EXPR:
- result = cxx_sizeof_or_alignof_expr (op0, opcode, true);
+ result = cxx_sizeof_or_alignof_expr (input_location,
+ op0, opcode, true);
break;
case DELETE_EXPR:
default:
/* Use the C++11 alignof semantics. */
- result = cxx_sizeof_or_alignof_type (type, opcode, true, true);
+ result = cxx_sizeof_or_alignof_type (input_location, type,
+ opcode, true, true);
}
if (template_dependent_p)