[llvm-bugs] [Bug 38980] New: Weird failure/interaction in substitution/specialization matching

via llvm-bugs llvm-bugs at lists.llvm.org
Mon Sep 17 21:32:11 PDT 2018


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: unassignedclangbugs at nondot.org
          Reporter: Casey at Carter.net
                CC: dgregor at apple.com, llvm-bugs at 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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20180918/2e9f4dff/attachment-0001.html>


More information about the llvm-bugs mailing list