]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
/cp
authorpaolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 11 Jun 2018 21:13:19 +0000 (21:13 +0000)
committerpaolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 11 Jun 2018 21:13:19 +0000 (21:13 +0000)
2018-06-11  Paolo Carlini  <paolo.carlini@oracle.com>

* decl.c (grok_op_properties): Consistently use the location
of the decl; remove special casing of POSTINCREMENT_EXPR and
POSTDECREMENT_EXPR wrt default arguments.

/testsuite
2018-06-11  Paolo Carlini  <paolo.carlini@oracle.com>

* g++.dg/lookup/new2.C: Test locations too.
* g++.dg/other/ellipsis1.C: Likewise.
* g++.dg/other/operator1.C: Likewise.
* g++.dg/other/operator2.C: Likewise.
* g++.dg/overload/operator2.C: Likewise.
* g++.dg/parse/defarg11.C: Likewise.
* g++.dg/parse/operator4.C: Likewise.
* g++.dg/template/error30.C: Likewise.
* g++.dg/template/explicit-args3.C: Likewise.
* g++.dg/warn/effc1.C: Likewise.
* g++.old-deja/g++.brendan/prepost2.C: Likewise.
* g++.old-deja/g++.brendan/prepost3.C: Likewise.
* g++.old-deja/g++.bugs/900215_01.C: Likewise.
* g++.old-deja/g++.jason/conversion5.C: Likewise.
* g++.old-deja/g++.jason/operator.C: Likewise.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@261455 138bc75d-0d04-0410-961f-82ee72b054a4

17 files changed:
gcc/cp/ChangeLog
gcc/cp/decl.c
gcc/testsuite/g++.dg/lookup/new2.C
gcc/testsuite/g++.dg/other/ellipsis1.C
gcc/testsuite/g++.dg/other/operator1.C
gcc/testsuite/g++.dg/other/operator2.C
gcc/testsuite/g++.dg/overload/operator2.C
gcc/testsuite/g++.dg/parse/defarg11.C
gcc/testsuite/g++.dg/parse/operator4.C
gcc/testsuite/g++.dg/template/error30.C
gcc/testsuite/g++.dg/template/explicit-args3.C
gcc/testsuite/g++.dg/warn/effc1.C
gcc/testsuite/g++.old-deja/g++.brendan/prepost2.C
gcc/testsuite/g++.old-deja/g++.brendan/prepost3.C
gcc/testsuite/g++.old-deja/g++.bugs/900215_01.C
gcc/testsuite/g++.old-deja/g++.jason/conversion5.C
gcc/testsuite/g++.old-deja/g++.jason/operator.C

index 4c7041b6cc416c10311f402432b8910203875be8..9458b4150a83e48ad9d60ced6c496398995f162e 100644 (file)
@@ -1,3 +1,9 @@
+2018-06-11  Paolo Carlini  <paolo.carlini@oracle.com>
+
+       * decl.c (grok_op_properties): Consistently use the location
+       of the decl; remove special casing of POSTINCREMENT_EXPR and
+       POSTDECREMENT_EXPR wrt default arguments.
+
 2018-06-05  Jason Merrill  <jason@redhat.com>
 
        * constexpr.c (cxx_eval_binary_expression): Special case comparison
index 688ba4a1442a8f884dd1466a28b021d81ba434eb..c8353405a1a6675a5ff77f8f3b4b7a910f50a5b6 100644 (file)
@@ -13078,6 +13078,7 @@ grok_op_properties (tree decl, bool complain)
   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))
@@ -13139,13 +13140,14 @@ grok_op_properties (tree decl, bool complain)
        {
          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;
            }
        }
@@ -13172,14 +13174,14 @@ grok_op_properties (tree decl, bool complain)
          || 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;
        }
 
@@ -13188,8 +13190,8 @@ grok_op_properties (tree decl, bool complain)
          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;
            }
       
@@ -13214,7 +13216,7 @@ grok_op_properties (tree decl, bool complain)
   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;
     }
 
@@ -13225,7 +13227,8 @@ grok_op_properties (tree decl, bool complain)
       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;
@@ -13248,9 +13251,10 @@ grok_op_properties (tree decl, bool complain)
       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
@@ -13260,10 +13264,11 @@ grok_op_properties (tree decl, bool complain)
               && ! 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;
@@ -13271,9 +13276,10 @@ grok_op_properties (tree decl, bool complain)
     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;
@@ -13281,9 +13287,10 @@ grok_op_properties (tree decl, bool complain)
     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;
@@ -13297,15 +13304,8 @@ grok_op_properties (tree decl, bool complain)
     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
@@ -13328,31 +13328,31 @@ grok_op_properties (tree decl, bool complain)
        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"));
        }
     }
 
@@ -13365,8 +13365,8 @@ grok_op_properties (tree decl, bool complain)
   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
@@ -13385,13 +13385,14 @@ grok_op_properties (tree decl, bool complain)
        {
          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);
        }
     }
 
@@ -13403,7 +13404,7 @@ grok_op_properties (tree decl, bool complain)
          || 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;
 }
index d468182c18b7307f40b9db80324014e25b8ebe31..0eee4a0018d440d0f389f0fe48b730da264aa4b6 100644 (file)
@@ -4,8 +4,8 @@
 
 namespace A {
   void* operator new(__SIZE_TYPE__ s, int* p); // { dg-error "namespace" }
-  void  operator delete(void*);                // { dg-error "namespace" }
+  void  operator delete(void*);                // { dg-error "9:.void A::operator delete\\(void\\*\\). may not be declared within a namespace" }
 }
 
 static void* operator new(__SIZE_TYPE__ s, int* p); // { dg-error "static" }
-static void  operator delete(void*);                // { dg-error "static" }
+static void  operator delete(void*);                // { dg-error "14:.void operator delete\\(void\\*\\). may not be declared as static" }
index d2501ca85e2c9733d0c1532d35d85b85833ee83e..54756b8d27c7e390464920c67734bda429f094a2 100644 (file)
@@ -3,10 +3,10 @@
 
 struct A
 {
-    A& operator= (A,...);  // { dg-error "variable number of arguments" }
-    A operator+ (...);     // { dg-error "variable number of arguments" }
-    operator int(...);     // { dg-error "variable number of arguments" }
+    A& operator= (A,...);  // { dg-error "8:.A& A::operator=\\(A, ...\\). must not have variable number of arguments" }
+    A operator+ (...);     // { dg-error "7:.A A::operator\\+\\(...\\). must not have variable number of arguments" }
+    operator int(...);     // { dg-error "5:.A::operator int\\(...\\). must not have variable number of arguments" }
     int operator() (...);
 };
 
-A operator- (A,...);       // { dg-error "variable number of arguments" }
+A operator- (A,...);       // { dg-error "3:.A operator-\\(A, ...\\). must not have variable number of arguments" }
index 86841c9995696a3220335481898107224dfc8744..d0b0cb25f8cfa89503b3985c57dd90bead4348c9 100644 (file)
@@ -1,7 +1,7 @@
 // PR c++/27547
 // { dg-do compile }
 
-int operator=(int);  // { dg-error "member function" }
+int operator=(int);  // { dg-error "5:.int operator=\\(int\\). must be a nonstatic member function" }
 
 void foo()
 {
index cc68d53354e4ffc817a8b0d9c2dade18c4e46e12..3587311271866273b8a2510f6bc90dfc31e26aee 100644 (file)
@@ -3,7 +3,7 @@
 
 struct A
 {
-  operator int&(int);  // { dg-error "no arguments" }
+  operator int&(int);  // { dg-error "3:.A::operator int&\\(int\\). must have no arguments" }
 };
 
 A a;
index aba1622442c62f87fd5d3f368af39420ce1fd04f..b60c629744ecfb4c28e8a1d951ed377487da4a7f 100644 (file)
@@ -3,12 +3,12 @@
 
 struct A
 {
-  static operator int(); // { dg-error "must be a nonstatic" }
+  static operator int(); // { dg-error "10:.static A::operator int\\(\\). must be a nonstatic member function" }
 };
 
 struct B
 {
-  static int operator*(); // { dg-error "must be either" }
+  static int operator*(); // { dg-error "14:.static int B::operator\\*\\(\\). must be either a non-static member function or a non-member function" }
 };
 
-static operator int(); // { dg-error "must be a nonstatic" }
+static operator int(); // { dg-error "8:.operator int\\(\\). must be a nonstatic member function" }
index 60199c2e20c9af3784bd71653fcb9eb6c57492dc..33f4b8ac70ad5d49a9d23392977ba020323ab64d 100644 (file)
@@ -3,7 +3,7 @@
 
 class foo {
 public:
-  void operator& (int = 1);  // { dg-error "default argument" }
-  void operator++ (int = 2); // { dg-warning "default argument" }
-  void operator-- (int = 3); // { dg-warning "default argument" }
+  void operator& (int = 1);  // { dg-error "8:.void foo::operator&\\(int\\). cannot have default arguments" }
+  void operator++ (int = 2); // { dg-error "8:.void foo::operator\\+\\+\\(int\\). cannot have default arguments" }
+  void operator-- (int = 3); // { dg-error "8:.void foo::operator--\\(int\\). cannot have default arguments" }
 };
index 054ddc8354f2ec210d79263589aee7b60d466599..1c81fbf2b444bf618a29dd2d601c76026eb061ef 100644 (file)
@@ -1 +1 @@
-int operator *(int, ...); // { dg-error "class|variable number of arguments" }
+int operator *(int, ...); // { dg-error ".int operator\\*\\(int, ...\\). must have an argument of class or enumerated type" }
index e1138d052ec2dc3d79ceaa8f29b9b178176cd807..e1706af0b7a6a03b13e06d6f36b9573d04271406 100644 (file)
@@ -2,4 +2,4 @@
 
 template<int> struct A;
 
-template<template<typename> class B> A<B<int>::x> operator() (); // { dg-error "A<B<int>::x>" }
+template<template<typename> class B> A<B<int>::x> operator() (); // { dg-error "51:.A<B<int>::x> operator\\(\\)\\(\\). must be a nonstatic member function" }
index c095e6688fdcf764174bce40bfeaf71f8a794212..5e16c21b3fd48fa0a5b40ff2e546b9421a89f844 100644 (file)
@@ -4,7 +4,7 @@ template <class T>
 struct A { };
 
 template <class T>
-void operator+(T, T);          // { dg-error "class or enum" }
+void operator+(T, T);          // { dg-error "6:.void operator\\+\\(T, T\\) \\\[with T = int\\\]. must have an argument of class or enumerated type" }
 
 int main()
 {
index db36b121304c3fe6903e160c08ca35f3d60aec8d..2911451ee6d07f8545f1ed8d9fd48651b0eea1fd 100644 (file)
@@ -10,7 +10,7 @@ class A
 {
   public:
   A & operator+=( int );
-  A & operator+( int ); // { dg-warning ".* should return by value" }
+  A & operator+( int );  // { dg-warning "7:.A& A::operator\\+\\(int\\). should return by value" }
   A operator+=( float );
   A operator+( float );
 };
index 3156749cff9c08740a89c1df611d057b7faf52ea..cbd05e647b132040af417e389f85d0acdf07a3ce 100644 (file)
@@ -4,7 +4,10 @@ class foo {
 public:
       operator ++ (); // { dg-error "" } no type or storage class
       operator ++ (int); // { dg-error "" } no type or storage class
-      operator ++ (char);              // illegal// { dg-error "" } .*
-      operator ++ (short);             // illegal// { dg-error "" } .*
-      operator ++ (long);              // illegal// { dg-error "" } .*
+      operator ++ (char);              // { dg-error "no type" }
+// { dg-error "7:postfix .int foo::operator\\+\\+\\(char\\). must have .int. as its argument" "sec" { target *-*-* } .-1 }
+      operator ++ (short);             // { dg-error "no type" }
+// { dg-error "7:postfix .int foo::operator\\+\\+\\(short int\\). must have .int. as its argument" "sec" { target *-*-* } .-1 }
+      operator ++ (long);              // { dg-error "no type" }
+// { dg-error "7:postfix .int foo::operator\\+\\+\\(long int\\). must have .int. as its argument" "sec" { target *-*-* } .-1 }
 };
index d11624b2d087b12c98a982a2471b4933b15fe472..f55c3dc35b3890f2c7700c0799ffc99387be2223 100644 (file)
@@ -3,5 +3,5 @@
 class Y {
 public:
    friend Y operator++ (Y&);
-   friend Y operator++ (Y&, char);     // illegal// { dg-error "" } .*
+   friend Y operator++ (Y&, char);  // { dg-error "13:postfix .Y operator\\+\\+\\(Y&, char\\). must have .int. as its second argument" }
 };
index c79a7035f99de1432976b95f7f7bd509aa6b85ac..0cd9b321e3e7d64d8fc04fc537a549d36b8cd292 100644 (file)
@@ -24,7 +24,7 @@
 
 struct struct0 {
 
-  operator void ();            // { dg-warning "" } operator void
+  operator void ();  // { dg-warning "3:conversion to void will never use a type conversion operator" }
 };
 
 int exit_status = 1;
index 0031084db004d4f8cadfd8436ec724e42ac71191..a9531a6d20916fec5e020cf849512d8b426dffef 100644 (file)
@@ -3,7 +3,7 @@
 struct A { };
 struct B: public A {
   A a;
-  operator A () { return a; }  // { dg-warning "" } never used implicitly
+  operator A () { return a; }  // { dg-warning "3:conversion to a base class will never use a type conversion operator" }
 };
 void f (const A&);
 void g()
index bdcd5493a97e57b134c1a444e017103d39725f59..ba6d407d1b9031048c89747d0ab585c6b0291ecd 100644 (file)
@@ -6,27 +6,27 @@ typedef __SIZE_TYPE__ size_t;
 
 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 }