[llvm-bugs] [Bug 42213] New: Invalid template parameter

via llvm-bugs llvm-bugs at lists.llvm.org
Sun Jun 9 17:23:50 PDT 2019


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

            Bug ID: 42213
           Summary: Invalid template parameter
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: C++
          Assignee: unassignedclangbugs at nondot.org
          Reporter: zhonghao at pku.org.cn
                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

My clang is 9.0.0, and the code is:


template < bool, class > struct A {};
template < class, int > void f () {};
template < class T, int >
decltype (f < T, 1 >) f (T t, typename A < t == 0, int >::type) {};

struct B {};

int main ()
{ 
 f < B, 0 >;
 return 0;
}


clang accepts the code, but icc, gcc, and msvc all reject it:

gcc:

<source>:5:56: error: wrong number of template arguments (1, should be 2)

    5 | decltype (f < T, 1 >) f (T t, typename A < t == 0, int >::type) {};

      |                                                        ^

<source>:2:33: note: provided for 'template<bool <anonymous>, class> struct A'

    2 | template < bool, class > struct A {};

      |                                 ^

<source>:5:40: error: expected nested-name-specifier before 'A'

    5 | decltype (f < T, 1 >) f (T t, typename A < t == 0, int >::type) {};

      |                                        ^

<source>:5:56: error: wrong number of template arguments (1, should be 2)

    5 | decltype (f < T, 1 >) f (T t, typename A < t == 0, int >::type) {};

      |                                                        ^

<source>:2:33: note: provided for 'template<bool <anonymous>, class> struct A'

    2 | template < bool, class > struct A {};

      |                                 ^

<source>:5:56: error: wrong number of template arguments (1, should be 2)

    5 | decltype (f < T, 1 >) f (T t, typename A < t == 0, int >::type) {};

      |                                                        ^

<source>:2:33: note: provided for 'template<bool <anonymous>, class> struct A'

    2 | template < bool, class > struct A {};

      |                                 ^

<source>:5:56: error: wrong number of template arguments (1, should be 2)

    5 | decltype (f < T, 1 >) f (T t, typename A < t == 0, int >::type) {};

      |                                                        ^

<source>:2:33: note: provided for 'template<bool <anonymous>, class> struct A'

    2 | template < bool, class > struct A {};

      |                                 ^

<source>:5:42: error: expected ',' or '...' before '<' token

    5 | decltype (f < T, 1 >) f (T t, typename A < t == 0, int >::type) {};

      |                                          ^

Compiler returned: 1

icc:

<source>(5): error: a parameter is not allowed

  decltype (f < T, 1 >) f (T t, typename A < t == 0, int >::type) {};

                                             ^

compilation aborted for <source> (code 2)

Compiler returned: 2

msvc:

example.cpp

<source>(5): error C2975: 'unnamed-parameter': invalid template argument for
'A', expected compile-time constant expression

<source>(2): note: see declaration of 'unnamed-parameter'

<source>(5): error C2039: 'type': is not a member of 'A<false,int>'

<source>(5): note: see declaration of 'A<false,int>'

<source>(5): error C4430: missing type specifier - int assumed. Note: C++ does
not support default-int

<source>(11): warning C4551: function call missing argument list

Compiler returned: 2

-- 
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/20190610/c4ac805e/attachment.html>


More information about the llvm-bugs mailing list