I just ran into this little error with msvc. This seems like a parsing problem, but I'm not sure.
The following gives me syntax error C2143: missing ';' before that '}'
#include <vector> struct X { }; X f(const std::vector<int> v) { for (auto i : v) if (true) return X{}; // <-- return X{}; } int main() { const auto x = f(std::vector<int>{}); }
The following 4 options compile just fine. it
X f(const std::vector<int> v) { for (auto i : v) if (true) return X();
and this one
X f(const std::vector<int> v) { for (auto i : v) if (true) {
and this one
X f(const std::vector<int> v) { for (auto i : v) {
and this one
X f(const std::vector<int> v) {
(Sorry for the wall of stupid code.)
Am I missing some secret rule or is it a compiler error?
Visual Studio 2015 (v140) Express Edition for the desktop
compiled as x64 in debug and release mode
all default compiler options (except for the warning level superimposed on W4)
source share