[llvm-bugs] [Bug 31771] New: Incorrect identification of Most Vexing Parse when expanding parameter pack and calling constructors
via llvm-bugs
llvm-bugs at lists.llvm.org
Thu Jan 26 10:12:41 PST 2017
https://llvm.org/bugs/show_bug.cgi?id=31771
Bug ID: 31771
Summary: Incorrect identification of Most Vexing Parse when
expanding parameter pack and calling constructors
Product: clang
Version: trunk
Hardware: PC
OS: Linux
Status: NEW
Severity: normal
Priority: P
Component: Frontend
Assignee: unassignedclangbugs at nondot.org
Reporter: victory at csail.mit.edu
CC: llvm-bugs at lists.llvm.org
Classification: Unclassified
In the C++11 program below, the indicated statement attempts to expand a
parameter pack to construct a Tuple object, used to initialize the variable
"s". Clang warns that this is a Vexing Parse and interprets the statement as a
function declaration, as well giving an error about mismatched parentheses. The
error indicates Clang realizes the statement cannot be parsed as a function
declaration. Since it isn't a function declaration, there is no ambiguity, and
Clang should reinterpret the statement as the definition and initialization of
variable "s" of type "S". I have verified that g++ has the desired behavior.
clang version 5.0.0 (trunk 293190)
Target: x86_64-unknown-linux-gnu
Thread model: posix
$ cat test.cpp
template <class ... Types>
struct Tuple {
Tuple(Types ...args) { }
} ;
template <class ... Types>
void f(Types ...args) {
struct S {
S(Tuple<Types...> t) { }
};
S s(Tuple<Types...>(args...)); // This line causes clang error!
}
int main() {
f<int,double>(1, 42.0);
return 0;
}
$ clang++ -std=c++11 -O0 -S -emit-llvm test.cpp
test.cpp:12:27: error: expected ')'
S s(Tuple<Types...>(args...)); // This line causes clang error!
^
test.cpp:12:22: note: to match this '('
S s(Tuple<Types...>(args...)); // This line causes clang error!
^
test.cpp:12:6: warning: parentheses were disambiguated as a function
declaration [-Wvexing-parse]
S s(Tuple<Types...>(args...)); // This line causes clang error!
^~~~~~~~~~~~~~~~~~~~~~~~~~
test.cpp:12:7: note: add a pair of parentheses to declare a variable
S s(Tuple<Types...>(args...)); // This line causes clang error!
^
( )
1 warning and 1 error 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/20170126/2c4e35bf/attachment.html>
More information about the llvm-bugs
mailing list