[llvm-bugs] [Bug 44034] Clang++ accepts invalid template code

via llvm-bugs llvm-bugs at lists.llvm.org
Mon Nov 18 14:49:06 PST 2019


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

Richard Smith <richard-llvm at metafoo.co.uk> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |WONTFIX

--- Comment #2 from Richard Smith <richard-llvm at metafoo.co.uk> ---
Well, the intent is that you are allowed to pass Args as explicit template
arguments:

  algorithm_impl::do_n<Function, Args...>(
                       std::forward<Function>(func),
                       std::forward<Args>(args)...,
                       std::make_integer_sequence<size_t, count>{});

... and in the case where Args is empty, you can instead write that as:

  algorithm_impl::do_n<Function>(
                       std::forward<Function>(func),
                       std::forward<Args>(args)...,
                       std::make_integer_sequence<size_t, count>{});

(This specifies Args as an empty pack.)

You can also omit the "Function" in this case, because it's deducible:

  algorithm_impl::do_n<>(
                       std::forward<Function>(func),
                       std::forward<Args>(args)...,
                       std::make_integer_sequence<size_t, count>{});

(This still -- presumably! -- specifies Args as an empty pack.)

And finally, [temp.arg.explicit]p4 says you can omit the empty <> in this case
and it means the same thing as including an <>:

  algorithm_impl::do_n(std::forward<Function>(func),
                       std::forward<Args>(args)...,
                       std::make_integer_sequence<size_t, count>{});

... so by that argument, the code is valid, and MSVC is wrong to reject it, and
Clang and GCC are correct to accept.

This whole area of the C++ standard is underspecified and imprecise, but the
behavior of Clang and GCC here is consistent, reasonable, and in line with
discussions on the C++ committee reflectors about how deduction should work.

MSVC rejects all of the above cases, so I think this is just an MSVC bug. (ICC
has even weirder behavior: it accepts the first two examples but rejects the
last two.)

We're unlikely to make any changes here unless the C++ standard text is
clarified to indicate Clang's behavior is incorrect, so I'm resolving WONTFIX
for now.

-- 
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/20191118/b1749043/attachment.html>


More information about the llvm-bugs mailing list