decl.c (grokdeclarator): Use rich_location::add_range in three more places; include...
authorPaolo Carlini <paolo.carlini@oracle.com>
Mon, 9 Jul 2018 07:59:22 +0000 (07:59 +0000)
committerPaolo Carlini <paolo@gcc.gnu.org>
Mon, 9 Jul 2018 07:59:22 +0000 (07:59 +0000)
/cp
2018-07-09  Paolo Carlini  <paolo.carlini@oracle.com>

* decl.c (grokdeclarator): Use rich_location::add_range in three
more places; include gcc-rich-location.h.

/testsuite
2018-07-09  Paolo Carlini  <paolo.carlini@oracle.com>

* g++.dg/diagnostic/long-short.C: New.
* g++.dg/diagnostic/signed-unsigned.C: Likewise.
* g++.dg/diagnostic/virtual-friend.C: Likewise.
* g++.old-deja/g++.brendan/crash11.C: Adjust.

From-SVN: r262512

gcc/cp/ChangeLog
gcc/cp/decl.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/diagnostic/long-short.C [new file with mode: 0644]
gcc/testsuite/g++.dg/diagnostic/signed-unsigned.C [new file with mode: 0644]
gcc/testsuite/g++.dg/diagnostic/virtual-friend.C [new file with mode: 0644]
gcc/testsuite/g++.old-deja/g++.brendan/crash11.C

index 9fb2b48f64ca0e299b5f29d4c8d888a9ec815768..82cb481ff779339d68dc575631e834daac0bc71d 100644 (file)
@@ -1,3 +1,8 @@
+2018-07-09  Paolo Carlini  <paolo.carlini@oracle.com>
+
+       * decl.c (grokdeclarator): Use rich_location::add_range in three
+       more places; include gcc-rich-location.h.
+
 2018-07-07  Aldy Hernandez  <aldyh@redhat.com>
 
        * decl.c (build_enumerator): Change overflow type to overflow_type.
index c879e8f8f3f5d7fe6054baf363e6c10f82061e15..3597ba046546dfd9602e4014929d09432bcf6916 100644 (file)
@@ -51,6 +51,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "builtins.h"
 #include "gimplify.h"
 #include "asan.h"
+#include "gcc-rich-location.h"
 
 /* Possible cases of bad specifiers type used by bad_specifiers. */
 enum bad_spec_place {
@@ -10580,9 +10581,18 @@ grokdeclarator (const cp_declarator *declarator,
       int ok = 0;
 
       if (signed_p && unsigned_p)
-       error_at (loc, "%<signed%> and %<unsigned%> specified together");
+       {
+         gcc_rich_location richloc (declspecs->locations[ds_signed]);
+         richloc.add_range (declspecs->locations[ds_unsigned], false);
+         error_at (&richloc,
+                   "%<signed%> and %<unsigned%> specified together");
+       }
       else if (long_p && short_p)
-       error_at (loc, "%<long%> and %<short%> specified together");
+       {
+         gcc_rich_location richloc (declspecs->locations[ds_long]);
+         richloc.add_range (declspecs->locations[ds_short], false);
+         error_at (&richloc, "%<long%> and %<short%> specified together");
+       }
       else if (TREE_CODE (type) != INTEGER_TYPE
               || type == char16_type_node || type == char32_type_node
               || ((long_p || short_p)
@@ -10723,7 +10733,7 @@ grokdeclarator (const cp_declarator *declarator,
     {
       if (staticp == 2)
        {
-         rich_location richloc (line_table, declspecs->locations[ds_virtual]);
+         gcc_rich_location richloc (declspecs->locations[ds_virtual]);
          richloc.add_range (declspecs->locations[ds_storage_class], false);
          error_at (&richloc, "member %qD cannot be declared both %<virtual%> "
                    "and %<static%>", dname);
@@ -10732,7 +10742,7 @@ grokdeclarator (const cp_declarator *declarator,
        }
       if (constexpr_p)
        {
-         rich_location richloc (line_table, declspecs->locations[ds_virtual]);
+         gcc_rich_location richloc (declspecs->locations[ds_virtual]);
          richloc.add_range (declspecs->locations[ds_constexpr], false);
          error_at (&richloc, "member %qD cannot be declared both %<virtual%> "
                    "and %<constexpr%>", dname);
@@ -11270,8 +11280,9 @@ grokdeclarator (const cp_declarator *declarator,
                if (virtualp)
                  {
                    /* Cannot be both friend and virtual.  */
-                   error_at (declspecs->locations[ds_friend],
-                             "virtual functions cannot be friends");
+                   gcc_rich_location richloc (declspecs->locations[ds_virtual]);
+                   richloc.add_range (declspecs->locations[ds_friend], false);
+                   error_at (&richloc, "virtual functions cannot be friends");
                    friendp = 0;
                  }
                if (decl_context == NORMAL)
index 988fac11b05b87e446ce5cce55e19eebb0a881b7..dae26a2e97d92600ec2cd58df61fbc70e64dc5ee 100644 (file)
@@ -1,3 +1,10 @@
+2018-07-09  Paolo Carlini  <paolo.carlini@oracle.com>
+
+       * g++.dg/diagnostic/long-short.C: New.
+       * g++.dg/diagnostic/signed-unsigned.C: Likewise.
+       * g++.dg/diagnostic/virtual-friend.C: Likewise.
+       * g++.old-deja/g++.brendan/crash11.C: Adjust.
+
 2018-07-09  Tom de Vries  <tdevries@suse.de>
 
        * gcc.dg/vla-1.c: New test.
diff --git a/gcc/testsuite/g++.dg/diagnostic/long-short.C b/gcc/testsuite/g++.dg/diagnostic/long-short.C
new file mode 100644 (file)
index 0000000..af82b37
--- /dev/null
@@ -0,0 +1,12 @@
+// { dg-options "-fdiagnostics-show-caret" }
+
+long short int a;  // { dg-error "1:.long. and .short. specified together" }
+/* { dg-begin-multiline-output "" }
+ long short int a;
+ ^~~~ ~~~~~
+   { dg-end-multiline-output "" } */
+short long int b;  // { dg-error "7:.long. and .short. specified together" }
+/* { dg-begin-multiline-output "" }
+ short long int b;
+ ~~~~~ ^~~~
+   { dg-end-multiline-output "" } */
diff --git a/gcc/testsuite/g++.dg/diagnostic/signed-unsigned.C b/gcc/testsuite/g++.dg/diagnostic/signed-unsigned.C
new file mode 100644 (file)
index 0000000..614783c
--- /dev/null
@@ -0,0 +1,12 @@
+// { dg-options "-fdiagnostics-show-caret" }
+
+signed unsigned int a;  // { dg-error "1:.signed. and .unsigned. specified together" }
+/* { dg-begin-multiline-output "" }
+ signed unsigned int a;
+ ^~~~~~ ~~~~~~~~
+   { dg-end-multiline-output "" } */
+unsigned signed int b;  // { dg-error "10:.signed. and .unsigned. specified together" }
+/* { dg-begin-multiline-output "" }
+ unsigned signed int b;
+ ~~~~~~~~ ^~~~~~
+   { dg-end-multiline-output "" } */
diff --git a/gcc/testsuite/g++.dg/diagnostic/virtual-friend.C b/gcc/testsuite/g++.dg/diagnostic/virtual-friend.C
new file mode 100644 (file)
index 0000000..c4f72bf
--- /dev/null
@@ -0,0 +1,16 @@
+// { dg-options "-fdiagnostics-show-caret" }
+// { dg-do compile { target c++11 } }
+
+struct S
+{
+  virtual friend void foo();  // { dg-error "3:virtual functions cannot be friends" }
+/* { dg-begin-multiline-output "" }
+   virtual friend void foo();
+   ^~~~~~~ ~~~~~~
+   { dg-end-multiline-output "" } */
+  friend virtual void bar();  // { dg-error "10:virtual functions cannot be friends" }
+/* { dg-begin-multiline-output "" }
+   friend virtual void bar();
+   ~~~~~~ ^~~~~~~
+   { dg-end-multiline-output "" } */
+};
index 246f5a03aa557642a823ab46598dce2033533744..96ebb71645c3fd0e11e272537c995e69aa824250 100644 (file)
@@ -9,13 +9,13 @@ class A {
        int     h;
        A() { i=10; j=20; }
        virtual void f1() { printf("i=%d j=%d\n",i,j); }
-       friend virtual void f2() { printf("i=%d j=%d\n",i,j); } // { dg-error "2:virtual functions cannot be friends" }
+       friend virtual void f2() { printf("i=%d j=%d\n",i,j); } // { dg-error "9:virtual functions cannot be friends" }
 };
 
 class B : public A {
     public:
        virtual void f1() { printf("i=%d j=%d\n",i,j); }// { dg-error "" }  member.*// ERROR -  member.*
-       friend virtual void f2() { printf("i=%d j=%d\n",i,j); }  // { dg-error "2:virtual functions cannot be friends" }
+       friend virtual void f2() { printf("i=%d j=%d\n",i,j); }  // { dg-error "9:virtual functions cannot be friends" }
 // { dg-error "private" "" { target *-*-* } .-1 }
 };