Hi,

it seems we can easily improve the location of this - not so uncommon in novice code - error to point to the 'static' keyword.

Tested x86_64-linux.

Thanks, Paolo.

/////////////////////

/cp
2018-12-12  Paolo Carlini  <paolo.carl...@oracle.com>

        * decl.c (grokdeclarator): Fix location of error message about
        static data member definition.

/testsuite
2018-12-12  Paolo Carlini  <paolo.carl...@oracle.com>

        * g++.dg/other/static5.C: New.
Index: cp/decl.c
===================================================================
--- cp/decl.c   (revision 267051)
+++ cp/decl.c   (working copy)
@@ -12724,7 +12724,8 @@ grokdeclarator (const cp_declarator *declarator,
            DECL_CONTEXT (decl) = ctype;
            if (staticp == 1)
              {
-               permerror (input_location, "%<static%> may not be used when 
defining "
+               permerror (declspecs->locations[ds_storage_class],
+                          "%<static%> may not be used when defining "
                           "(as opposed to declaring) a static data member");
                staticp = 0;
                storage_class = sc_none;
Index: testsuite/g++.dg/other/static5.C
===================================================================
--- testsuite/g++.dg/other/static5.C    (nonexistent)
+++ testsuite/g++.dg/other/static5.C    (working copy)
@@ -0,0 +1,8 @@
+struct S
+{
+  static int i;
+  const static double d;
+};
+
+static int S::i;  // { dg-error "1:.static. may not be used" }
+const static double S::d = 1.0;  // { dg-error "7:.static. may not be used" }

Reply via email to