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

            Bug ID: 81339
           Summary: no error for invalid decltype(T()) expression in
                    immediate context
           Product: gcc
           Version: 8.0
            Status: UNCONFIRMED
          Keywords: accepts-invalid
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: redi at gcc dot gnu.org
  Target Milestone: ---

struct true_type { static const bool value = true; };
struct false_type { static const bool value = false; };

template <typename T>
struct IsDefaultConstructibleT
{
    // using T here (instead of U) should be an error
    template <typename U, typename = decltype(T())>
      static true_type test(void*);

    template <typename U>
      static false_type test(...);

    static constexpr bool value = decltype(test<T>(nullptr))::value;
};

struct S {
  S() = delete;
};

static_assert( IsDefaultConstructibleT<S>::value, "" ); // wrong

This should fail to compile, because T() is invalid, and is not a substitution
failure, but GCC compiles it, and even selects the true_type overload (so the
static assertion passes, which is doubly wrong).

Clang says:

n.cc:8:47: error: call to deleted constructor of 'S'
    template <typename U, typename = decltype(T())>
                                              ^
n.cc:21:16: note: in instantiation of template class
'IsDefaultConstructibleT<S>' requested here
static_assert( IsDefaultConstructibleT<S>::value, "" );
               ^
n.cc:18:3: note: 'S' has been explicitly marked deleted here
  S() = delete;
  ^
n.cc:21:1: error: static_assert failed ""
static_assert( IsDefaultConstructibleT<S>::value, "" );
^              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2 errors generated.

And EDG says:

"n.cc", line 8: error: the default constructor of "S" cannot be referenced --
          it is a deleted function
      template <typename U, typename = decltype(T())>
                                                ^
          detected during instantiation of class "IsDefaultConstructibleT<T>
                    [with T=S]" at line 21

1 error detected in the compilation of "n.cc".

Reply via email to