[llvm-bugs] [Bug 50989] New: ICE on valid, templated friend injection cause ICE, invalid template parameters, true and false at the same time assert condition

via llvm-bugs llvm-bugs at lists.llvm.org
Mon Jul 5 17:48:04 PDT 2021


https://bugs.llvm.org/show_bug.cgi?id=50989

            Bug ID: 50989
           Summary: ICE on valid, templated friend injection cause ICE,
                    invalid template parameters, true and false at the
                    same time assert condition
           Product: clang
           Version: 8.0
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++
          Assignee: unassignedclangbugs at nondot.org
          Reporter: bastienPenava at gmail.com
                CC: blitzrakete at gmail.com, dgregor at apple.com,
                    erik.pilkington at gmail.com, llvm-bugs at lists.llvm.org,
                    richard-llvm at metafoo.co.uk

Hi,

I've stumbled upon a really weird bug with how friends are handled by clang.
The following causes invalid template parameters to be introduced and an ICE.

It's present since clang 8.0 and is still present in trunk.
Befoer clang 8, the friend was just never instantiated, which was also invalid.

Here a compiler-explorer link to the issue: https://godbolt.org/z/qzM41rrKG

Or here, the a minimal example:
```
#include <type_traits>

template<class...> struct type_t {};

struct A {};

template<class... Args>
void fn(A, type_t<Args...>);

template<int N>
void nothing() {}

struct fn_arg {};
struct class_arg {};

template<class T>
struct B
{
    template<class... Args>
    friend void fn(A, type_t<Args...>) {
        static_assert(std::is_same<T, fn_arg>::value, "Should be class_arg!");

        static_assert(sizeof...(Args) != 0, "ok");
        static_assert(sizeof...(Args) == 0, "What?");
        constexpr auto n = sizeof...(Args);
        nothing<n>(); //ICE!
    }
};

void func(B<class_arg> = {}) {}

int main()
{
    fn(A{}, type_t<fn_arg>{});
}

```

Thanks in advance

-- 
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/20210706/a70e1690/attachment.html>


More information about the llvm-bugs mailing list