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

            Bug ID: 79802
           Summary: Conflicting declaration with function pointers/types
           Product: gcc
           Version: 7.0.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: lutztonineubert at gmail dot com
  Target Milestone: ---

Using any g++ with flag -std=c++11 (14 or 17):

```
template<typename T>
struct Foo {
  void set(int i)  {
  }
  static constexpr decltype(&Foo<T>::set) i = &Foo<T>::set;
};

template<typename T>
constexpr decltype(&Foo<T>::set) Foo<T>::i;
```

Results in:

> conflicting declaration 'constexpr decltype (& Foo<T>::set(int))   Foo<T>::i'
> note: previous declaration as 'constexpr decltype (& Foo<T>::set(int)) 
> Foo<T>::i'

The problem exists with c++1(1,4,7) since GCC 4.7. No problem with clang >=
3.2.

A annoying workaround is to use a typedef of the function (compiles fine):

```
template<typename T>
struct Foo {
  void set(int i)  {
  }

  typedef decltype(&Foo<T>::set) function_type;
  static constexpr function_type i = &Foo<T>::set;
};

template<typename T>
constexpr typename Foo<T>::function_type Foo<T>::i;
```

Maybe similar to:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70943
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=57401

Please see also:
http://stackoverflow.com/questions/42534051/conflicting-declaration-for-static-variable-with-template-class

Reply via email to