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

            Bug ID: 38980
           Summary: Weird failure/interaction in
                    substitution/specialization matching
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++
          Assignee: unassignedclangb...@nondot.org
          Reporter: ca...@carter.net
                CC: dgre...@apple.com, llvm-bugs@lists.llvm.org

Compiling this correct program with -std=c++1z:

  template<class, class> constexpr bool is_same_v = false;
  template<class T> constexpr bool is_same_v<T, T> = true;

  template<class...> using void_t = void;

  template<class T> struct id { using type = T; };

  template<class T> T val() noexcept;

  template<class X, class Y> using cond_res = 
      decltype(false ? val<const X&>() : val<const Y&>());

  template<class, class, class = void>
  struct CT { using type = void; };

  template<class D1, class D2>
  #ifndef WORKAROUND
  struct CT<D1, D2, void_t<cond_res<D1, D2>>> : id<cond_res<D1, D2>> {};
  #else
  struct CT<D1, D2, void_t<cond_res<D1, D2>>> {
      using type = cond_res<D1, D2>;
  };
  #endif

  struct S1 {};
  struct S2 : private S1 {};
  struct S3 : protected S1 {};

  static_assert(is_same_v<void, CT<S1, S2>::type>); // Fine
  static_assert(is_same_v<void, CT<S1, S3>::type>); // Error

produces diagnostices (https://godbolt.org/z/WGvIFN):

  <source>:11:40: error: cannot cast 'const S3' to its protected base class 
  'const S1'
    decltype(false ? val<const X&>() : val<const Y&>());
                                       ^
  <source>:18:50: note: in instantiation of template type alias 'cond_res' 
  requested here
  struct CT<D1, D2, void_t<cond_res<D1, D2>>> : id<cond_res<D1, D2>> {};
                                                 ^
  <source>:30:31: note: in instantiation of template class 'CT<S1, S3, 
  void>' requested here
  static_assert(is_same_v<void, CT<S1, S3>::type>); // Error
                              ^
  <source>:27:13: note: declared protected here
  struct S3 : protected S1 {};
              ^~~~~~~~~~~~
  1 error generated.

Private base class? Fine. Protected base class? *EXPLODES*

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to