This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/78157] New: Incorrect diagnostic for variable template declaration


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78157

            Bug ID: 78157
           Summary: Incorrect diagnostic for variable template declaration
           Product: gcc
           Version: 6.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: kfischer at college dot harvard.edu
  Target Milestone: ---

Consider the following:

```
template <class S> class A {
  template<class T, class U> static T pi;
};
template <> template <class T> double A<int>::pi<double, T> =
3.1415926535897932385;
extern template double A<int>::pi<double, int>;
template double A<int>::pi<double, int>;
```

GCC complains:
```
test2.cpp:4:47: error: conflicting declaration ‘double A<int>::pi<double, T>’
 template <> template <class T> double A<int>::pi<double, T> =
3.1415926535897932385;
                                               ^~~~~~~~~~~~~
test2.cpp:2:39: note: previous declaration as ‘T A<int>::pi<T, U>’
   template<class T, class U> static T pi;
                                       ^~
test2.cpp:4:47: error: got 1 template parameters for ‘T A<int>::pi<T, U>’
 template <> template <class T> double A<int>::pi<double, T> =
3.1415926535897932385;
                                               ^~~~~~~~~~~~~
test2.cpp:4:47: error:   but 2 required
test2.cpp: In instantiation of ‘double A<int>::pi<double, int>’:
test2.cpp:6:25:   required from here
test2.cpp:6:25: error: explicit instantiation of ‘A<int>::pi<double, int>’ but
no definition available [-fpermissive]
 template double A<int>::pi<double, int>;
                         ^~~~~~~~~~~~~~~
```

Clang accepts this without error. ICC complains that the partial specialization
is
not allowed. I don't know whether or not this code is actually valid C++ or
not,
but either way, the diagnostic seems off, since there are two template
parameters
provided.

Godbolt links:
GCC 7: https://godbolt.org/g/W6OsWw
Clang: https://godbolt.org/g/3h8s93

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]