From: Paolo Carlini Date: Tue, 12 Jun 2018 21:22:10 +0000 (+0000) Subject: decl2.c (coerce_new_type, [...]): Add location_t parameter and adjust error_at calls. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=2d10ccaa001ba9cb367ee8d8d34512454d6bb293;p=gcc.git decl2.c (coerce_new_type, [...]): Add location_t parameter and adjust error_at calls. /cp 2018-06-12 Paolo Carlini * decl2.c (coerce_new_type, coerce_delete_type): Add location_t parameter and adjust error_at calls. * decl.c (grok_op_properties): Adjust calls. * cp-tree.h (oerce_new_type, coerce_delete_type): Adjust decls. /testsuite 2018-06-12 Paolo Carlini * g++.dg/init/delete3.C: New. * g++.dg/init/new49.C: Likewise. * g++.dg/init/new25.C: Test locations too. * g++.dg/template/new4.C: Likewise. * g++.old-deja/g++.jason/operator.C: Likewise. From-SVN: r261527 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 726fd7f6c43..05105ae7cfe 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,10 @@ +2018-06-12 Paolo Carlini + + * decl2.c (coerce_new_type, coerce_delete_type): Add location_t + parameter and adjust error_at calls. + * decl.c (grok_op_properties): Adjust calls. + * cp-tree.h (oerce_new_type, coerce_delete_type): Adjust decls. + 2018-06-12 Marek Polacek Core issue 1331 - const mismatch with defaulted copy constructor diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index a6d0b431a9d..59ad38107a8 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -6346,8 +6346,8 @@ extern bool attributes_naming_typedef_ok (tree); extern void cplus_decl_attributes (tree *, tree, int); extern void finish_anon_union (tree); extern void cxx_post_compilation_parsing_cleanups (void); -extern tree coerce_new_type (tree); -extern tree coerce_delete_type (tree); +extern tree coerce_new_type (tree, location_t); +extern tree coerce_delete_type (tree, location_t); extern void comdat_linkage (tree); extern void determine_visibility (tree); extern void constrain_class_visibility (tree); diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index c8353405a1a..de1b3415afb 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -13153,11 +13153,11 @@ grok_op_properties (tree decl, bool complain) } if (op_flags & OVL_OP_FLAG_DELETE) - TREE_TYPE (decl) = coerce_delete_type (TREE_TYPE (decl)); + TREE_TYPE (decl) = coerce_delete_type (TREE_TYPE (decl), loc); else { DECL_IS_OPERATOR_NEW (decl) = 1; - TREE_TYPE (decl) = coerce_new_type (TREE_TYPE (decl)); + TREE_TYPE (decl) = coerce_new_type (TREE_TYPE (decl), loc); } return true; diff --git a/gcc/cp/decl2.c b/gcc/cp/decl2.c index 2cef9c750ed..cbe2f2250f2 100644 --- a/gcc/cp/decl2.c +++ b/gcc/cp/decl2.c @@ -1676,7 +1676,7 @@ finish_anon_union (tree anon_union_decl) what compiler will be expecting. */ tree -coerce_new_type (tree type) +coerce_new_type (tree type, location_t loc) { int e = 0; tree args = TYPE_ARG_TYPES (type); @@ -1686,7 +1686,8 @@ coerce_new_type (tree type) if (!same_type_p (TREE_TYPE (type), ptr_type_node)) { e = 1; - error ("% must return type %qT", ptr_type_node); + error_at (loc, "% must return type %qT", + ptr_type_node); } if (args && args != void_list_node) @@ -1697,8 +1698,8 @@ coerce_new_type (tree type) The first parameter shall not have an associated default argument. */ - error ("the first parameter of % cannot " - "have a default argument"); + error_at (loc, "the first parameter of % cannot " + "have a default argument"); /* Throw away the default argument. */ TREE_PURPOSE (args) = NULL_TREE; } @@ -1713,7 +1714,7 @@ coerce_new_type (tree type) e = 2; if (e == 2) - permerror (input_location, "% takes type % (%qT) " + permerror (loc, "% takes type % (%qT) " "as first parameter", size_type_node); switch (e) @@ -1732,7 +1733,7 @@ coerce_new_type (tree type) } tree -coerce_delete_type (tree type) +coerce_delete_type (tree type, location_t loc) { int e = 0; tree args = TYPE_ARG_TYPES (type); @@ -1742,7 +1743,8 @@ coerce_delete_type (tree type) if (!same_type_p (TREE_TYPE (type), void_type_node)) { e = 1; - error ("% must return type %qT", void_type_node); + error_at (loc, "% must return type %qT", + void_type_node); } if (!args || args == void_list_node @@ -1751,8 +1753,8 @@ coerce_delete_type (tree type) e = 2; if (args && args != void_list_node) args = TREE_CHAIN (args); - error ("% takes type %qT as first parameter", - ptr_type_node); + error_at (loc, "% takes type %qT as first parameter", + ptr_type_node); } switch (e) { diff --git a/gcc/testsuite/g++.dg/init/delete3.C b/gcc/testsuite/g++.dg/init/delete3.C new file mode 100644 index 00000000000..d109440f6e4 --- /dev/null +++ b/gcc/testsuite/g++.dg/init/delete3.C @@ -0,0 +1 @@ +int operator delete (void*, int); // { dg-error "5:.operator delete. must return type .void." } diff --git a/gcc/testsuite/g++.dg/init/new25.C b/gcc/testsuite/g++.dg/init/new25.C index 3abd2f7aba0..7ca57acd8c2 100644 --- a/gcc/testsuite/g++.dg/init/new25.C +++ b/gcc/testsuite/g++.dg/init/new25.C @@ -4,14 +4,14 @@ class C { public: - void* operator new(std::size_t = 32) throw (std::bad_alloc); // { dg-error "first parameter" } + void* operator new(std::size_t = 32) throw (std::bad_alloc); // { dg-error "9:the first parameter of .operator new. cannot have a default argument" } // { dg-error "dynamic exception specification" "" { target c++17 } .-1 } // { dg-warning "deprecated" "" { target { c++11 && { ! c++17 } } } .-2 } - void* operator new[](std::size_t = 32) throw (std::bad_alloc); // { dg-error "first parameter" } + void* operator new[](std::size_t = 32) throw (std::bad_alloc); // { dg-error "9:the first parameter of .operator new. cannot have a default argument" } // { dg-error "dynamic exception specification" "" { target c++17 } .-1 } // { dg-warning "deprecated" "" { target { c++11 && { ! c++17 } } } .-2 } - void* operator new(std::size_t = 32, const std::nothrow_t&) throw(); // { dg-error "first parameter" } - void* operator new[](std::size_t = 32, const std::nothrow_t&) throw(); // { dg-error "first parameter" } + void* operator new(std::size_t = 32, const std::nothrow_t&) throw(); // { dg-error "9:the first parameter of .operator new. cannot have a default argument" } + void* operator new[](std::size_t = 32, const std::nothrow_t&) throw(); // { dg-error "9:the first parameter of .operator new. cannot have a default argument" } }; class D @@ -26,8 +26,8 @@ public: class E { public: - void* operator new(std::size_t = 0, - const std::nothrow_t& = std::nothrow_t()) throw(); // { dg-error "first parameter" } - void* operator new[](std::size_t = 0, - const std::nothrow_t& = std::nothrow_t()) throw(); // { dg-error "first parameter" } + void* operator new(std::size_t = 0, // { dg-error "9:the first parameter of .operator new. cannot have a default argument" } + const std::nothrow_t& = std::nothrow_t()) throw(); + void* operator new[](std::size_t = 0, // { dg-error "9:the first parameter of .operator new. cannot have a default argument" } + const std::nothrow_t& = std::nothrow_t()) throw(); }; diff --git a/gcc/testsuite/g++.dg/init/new49.C b/gcc/testsuite/g++.dg/init/new49.C new file mode 100644 index 00000000000..23259bdab16 --- /dev/null +++ b/gcc/testsuite/g++.dg/init/new49.C @@ -0,0 +1 @@ +int operator new (__SIZE_TYPE__, int); // { dg-error "5:.operator new. must return type .void*." } diff --git a/gcc/testsuite/g++.dg/template/new4.C b/gcc/testsuite/g++.dg/template/new4.C index bf6f06100c7..914c3c64819 100644 --- a/gcc/testsuite/g++.dg/template/new4.C +++ b/gcc/testsuite/g++.dg/template/new4.C @@ -4,5 +4,6 @@ struct A { template - static void* operator new(T) {} // { dg-error "first parameter|invalid template" } + static void* operator new(T) {} // { dg-error "invalid template" } +// { dg-error "18:.operator new. takes type .size_t." "first" { target *-*-* } .-1 } }; diff --git a/gcc/testsuite/g++.old-deja/g++.jason/operator.C b/gcc/testsuite/g++.old-deja/g++.jason/operator.C index ba6d407d1b9..c2fc212cef0 100644 --- a/gcc/testsuite/g++.old-deja/g++.jason/operator.C +++ b/gcc/testsuite/g++.old-deja/g++.jason/operator.C @@ -25,8 +25,8 @@ struct B { 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" } +void * operator new (A a); // { dg-error ".operator new. takes type .size_t." } +void operator delete (A a); // { dg-error ".operator delete. takes type .void\\*. as first parameter" } char * operator char * (int); // { dg-error "return type" "ret" } // { dg-error "8:.operator char\\*\\*\\(int\\). must be a nonstatic member function" "mem" { target *-*-* } .-1 }