[llvm-bugs] [Bug 41062] New: Compile error for nested template alias

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Mar 13 18:34:27 PDT 2019


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

            Bug ID: 41062
           Summary: Compile error for nested template alias
           Product: clang
           Version: 6.0
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: C++
          Assignee: unassignedclangbugs at nondot.org
          Reporter: liwei.cpp 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

// The code is as follows:

#include <type_traits>
using namespace std;

template <bool Add> struct Fun_;

template <>
struct Fun_<true> {
    template <typename T>
    using type = std::add_lvalue_reference<T>;
};

template <>
struct Fun_<false> {
    template <typename T>
    using type = std::remove_reference<T>;
};

template <typename T>
template <bool Add>
using Fun = typename Fun_<Add>::template type<T>;

template <typename T>
using Res_ = Fun<false>;

int main()
{
    Res_<int&>::type h = 3;
    return 0;
}

Gcc 7.3 could compile it, but clang 6.0 reports error as follows:

./main.cpp:20:1: error: extraneous template parameter list in alias template
declaration
using Fun = typename Fun_<Add>::template type<T>;
^
./main.cpp:23:18: error: template argument for template type parameter must be
a type
using Res_ = Fun<false>;
                 ^~~~~
./main.cpp:18:20: note: template parameter is declared here
template <typename T>
                   ^
./main.cpp:27:5: error: use of undeclared identifier 'Res_'
    Res_<int&>::type h = 3;
    ^
./main.cpp:27:13: error: expected '(' for function-style cast or type
construction
    Res_<int&>::type h = 3;
         ~~~^
./main.cpp:27:14: error: expected expression
    Res_<int&>::type h = 3;
             ^
./main.cpp:27:17: error: no member named 'type' in the global namespace
    Res_<int&>::type h = 3;
              ~~^
6 errors generated.

-- 
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/20190314/bd5c9598/attachment-0001.html>


More information about the llvm-bugs mailing list