[llvm-bugs] [Bug 46582] New: static_assert that is always false impossible?

via llvm-bugs llvm-bugs at lists.llvm.org
Sat Jul 4 05:18:41 PDT 2020


            Bug ID: 46582
           Summary: static_assert that is always false impossible?
           Product: new-bugs
           Version: unspecified
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: new bugs
          Assignee: unassignedbugs at nondot.org
          Reporter: D.Bahadir at GMX.de
                CC: htmldeveloper at gmail.com, llvm-bugs at lists.llvm.org

Reading https://devblogs.microsoft.com/oldnewthing/20200319-00/?p=103572 I
assumed it should be possible to put a `static_assert` into a base-template
which is always `false` if instantiated.

The following is an example:

#include <type_traits>

template <typename T>
int square(T num)
    static_assert(std::is_same_v<std::void_t<T>, int>, "FAILURE");
    return num * num;

template <>
int square(double num)
    return num * num;

void test()
    //square(1);  // Always fails.
    square(1.0);  // Should not fail but does in Clang.

Here, I am only calling the specialization of the template and in the
base-template `T` should be a dependent type that is not evaluated before
instantiation (due to `std::void_t`).

However, that only seems to be true for GCC but not Clang.
(See: https://godbolt.org/z/44zbae)

Is that a bug in GCC or Clang?

You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20200704/9be027fa/attachment-0001.html>

More information about the llvm-bugs mailing list