C++14 decltype(auto) 使 CLion 高亮显示为错误是一个有效的语句
C++14 decltype(auto) makes CLion highlight as error a valid statement
我正在使用 Scott Meyer 的 Effective Modern C++(第 3 项)做一些练习。
使用以下代码:
template<class T>
class Container
{
private:
T _arr[4];
public:
T &operator[](std::size_t index)
{
return _arr[index];
}
explicit Container(T def)
{
for(std::size_t i = 0; i < 4; ++i)
{
_arr[i] = def;
}
}
};
template<class C>
decltype(auto) print_and_access4(C&& container, std::size_t index)
{
std::cout << "Index = " << index << std::endl;
return container[index];
}
auto& y = print_and_access4(Container<int>(5), 0);
Clion 在最后一行抱怨:
那么,这个投诉是关于什么的?
P.S。使用 g++ --std=c++14 main.cpp
编译不会产生任何错误或警告。
g++ -v:
Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 9.0.0 (clang-900.0.39.2)
CLion 版本:
CLion 2017.3.2
Clion C++ 解析器目前不完全符合标准。所以有时它在有效代码上显示错误,有时在无效代码上不显示错误。但它会随着版本的不同而变得更好,所以可能会很快修复。
您可以在他们的跟踪器上报告错误:
https://youtrack.jetbrains.com/issues/CPP
如果您想要一些符合标准的 IDE,您可以尝试 IDE 基于 Clang 的东西,例如 QtCreator 或 KDevelop。
我正在使用 Scott Meyer 的 Effective Modern C++(第 3 项)做一些练习。
使用以下代码:
template<class T>
class Container
{
private:
T _arr[4];
public:
T &operator[](std::size_t index)
{
return _arr[index];
}
explicit Container(T def)
{
for(std::size_t i = 0; i < 4; ++i)
{
_arr[i] = def;
}
}
};
template<class C>
decltype(auto) print_and_access4(C&& container, std::size_t index)
{
std::cout << "Index = " << index << std::endl;
return container[index];
}
auto& y = print_and_access4(Container<int>(5), 0);
Clion 在最后一行抱怨:
那么,这个投诉是关于什么的?
P.S。使用 g++ --std=c++14 main.cpp
编译不会产生任何错误或警告。
g++ -v:
Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 9.0.0 (clang-900.0.39.2)
CLion 版本:
CLion 2017.3.2
Clion C++ 解析器目前不完全符合标准。所以有时它在有效代码上显示错误,有时在无效代码上不显示错误。但它会随着版本的不同而变得更好,所以可能会很快修复。
您可以在他们的跟踪器上报告错误: https://youtrack.jetbrains.com/issues/CPP
如果您想要一些符合标准的 IDE,您可以尝试 IDE 基于 Clang 的东西,例如 QtCreator 或 KDevelop。