[LLVMbugs] [Bug 19714] New: C++1y "void is a literal type" should be accepted in C++11 mode with a warning
bugzilla-daemon at llvm.org
bugzilla-daemon at llvm.org
Sun May 11 13:44:44 PDT 2014
http://llvm.org/bugs/show_bug.cgi?id=19714
Bug ID: 19714
Summary: C++1y "void is a literal type" should be accepted in
C++11 mode with a warning
Product: clang
Version: 3.4
Hardware: All
OS: All
Status: NEW
Severity: normal
Priority: P
Component: C++11
Assignee: unassignedclangbugs at nondot.org
Reporter: arthur.j.odwyer at gmail.com
CC: dgregor at apple.com, llvmbugs at cs.uiuc.edu
Classification: Unclassified
cat >test.cc <<EOF
#include <stdio.h>
template<typename T> void print_if_not_int(T t) { puts("hi"); }
template<> constexpr void print_if_not_int<int>(int) { }
int main() { print_if_not_int(1); }
EOF
clang++ -std=c++11 test.cc
test.cc:3:27: error: constexpr function's return type 'void' is not a
literal type
template<> constexpr void print_if_not_int<int>(int) { }
^
test.cc:4:14: error: no matching function for call to 'print_if_not_int'
int main() { print_if_not_int(1); }
^~~~~~~~~~~~~~~~
test.cc:2:27: note: candidate template ignored: substitution failure [with
T = int]
template<typename T> void print_if_not_int(T t) { puts("hi"); }
^
2 errors generated.
Apparently Standard C++11 requires the programmer to remember to type "inline"
instead of "constexpr" in cases where the function's return type is "void".
However, GNU GCC doesn't require any such thing, which means that there are
GCC-compatible programs floating around out there which don't build (and give
weird, unsuppressible substitution-failure errors) with Clang.
C++14 permits "constexpr" to be used with a "void" function.
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2012/n3444.html
Clang should allow the programmer to use this GCC and/or C++14 feature in their
C++11 programs, if possible. Introducing a new diagnostic something like
-Wvoid-literal-type (warning by default in C++11 mode) would enable the
programmer to use this feature without necessarily pulling in all of C++14.
I don't know whether there's any Standard justification for simply *allowing*
void as a literal type in C++11 mode. I know in some cases the resolutions of
DRs are "back-ported" into older standards if it's determined that they fix
"bugs" in the older standards. I don't know if this particular issue qualifies
for that kind of treatment.
--
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/20140511/5cbceab0/attachment.html>
More information about the llvm-bugs
mailing list