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

            Bug ID: 100498
           Summary: SFINAE and static inline function
           Product: gcc
           Version: 7.5.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: wolfgang.roe...@gi-de.com
  Target Milestone: ---

Hi,

I would like to post a bug report for the GNU C/C++ compiler 7.5.0.

We use the compiler to generate code for a PowerPC processor.

Invokation line for the GNU C++ compiler:

ccppc -c -x c++ --std=gnu++17 -Wall -Werror -g -mcpu=e6500 -m32
      -maltivec -mvrsave -ftls-model=local-exec -msdata=sysv
      -fno-common -fno-openmp -mbig -mmultiple -mno-string -misel
      -mstrict-align -fverbose-asm -G 8 -O3
      -I<some include paths>
      -D<some #define's>
      X.CPP -oX.O

// file X.CPP

void f1 (int) {}
inline void f1 (float) {}

struct X
{
    friend void f1 (int*) {}
};
void f1 (int*);


template <typename F_, typename = void>
struct SFINAE
{ static constexpr F_* ptr = nullptr; };

template <typename F_>
struct SFINAE< F_, decltype((void)static_cast<F_*>(f1), void()) >
{ static constexpr F_* ptr = f1; };


void func ()
{
    using F1 = void(int);
    constexpr F1* ptr1{ SFINAE<F1>::ptr };
    static_assert (ptr1 != nullptr);

    using F2 = void(float);
    constexpr F2* ptr2{ SFINAE<F2>::ptr };
    static_assert (ptr2 != nullptr);

    using F3 = void(int*);
    constexpr F3* ptr3{ SFINAE<F3>::ptr };
    static_assert (ptr3 != nullptr);
}


Wenn we compile this program we get the following error messages:
x.CPP: In function 'void func()':
x.CPP:29:5: error: non-constant condition for static assertion
     static_assert (ptr2 != nullptr);
     ^~~~~~~~~~~~~
x.CPP:29:25: error: '(f1 != 0)' is not a constant expression
     static_assert (ptr2 != nullptr);
                    ~~~~~^~~~~~~~~~
x.CPP:33:5: error: non-constant condition for static assertion
     static_assert (ptr3 != nullptr);
     ^~~~~~~~~~~~~
x.CPP:33:25: error: '(f1 != 0)' is not a constant expression
     static_assert (ptr3 != nullptr);
                    ~~~~~^~~~~~~~~~

The reason for the first error messages is the inline attribute of function
"void f1 (float)"; the error messages disappear if "inline" is removed. I
I think this is not standard compliant.
A similar problem seems to arise with function "void f1 (int*)". 


With kind regards
W. Roehrl

Reply via email to