Eclipse CDT 对 c++14 的解析器支持

Eclipse CDT parser support for c++14

编译器认为有效的东西和 IDE 认为的东西之间的良好脱节...在介绍重复的问题/答案之前,我必须强调 一切 可用在这里和其他地方的问题上,我已经尝试并提炼成这个设置:

检查编译器设置发现的日志,它已针对 C++14 正确配置:

03:51:39 **** Running scanner discovery: CDT GCC Built-in Compiler Settings MinGW ****
g++ -E -P -v -dD C:/dev/eclipse-oxy-cpp/.metadata/.plugins/org.eclipse.cdt.managedbuilder.core/spec.C 
Using built-in specs.
COLLECT_GCC=g++
Target: x86_64-w64-mingw32
Configured with: ../../../src/gcc-6.1.0/configure --host=x86_64-w64-mingw32 --build=x86_64-w64-mingw32 --target=x86_64-w64-mingw32 --prefix=/mingw64 --with-sysroot=/c/mingw610/x86_64-610-posix-seh-rt_v5/mingw64 --enable-shared --enable-static --disable-multilib --enable-languages=c,c++,fortran,lto --enable-libstdcxx-time=yes --enable-threads=posix --enable-libgomp --enable-libatomic --enable-lto --enable-graphite --enable-checking=release --enable-fully-dynamic-string --enable-version-specific-runtime-libs --enable-libstdcxx-filesystem-ts=yes --disable-isl-version-check --disable-libstdcxx-pch --disable-libstdcxx-debug --enable-bootstrap --disable-rpath --disable-win32-registry --disable-nls --disable-werror --disable-symvers --with-gnu-as --with-gnu-ld --with-arch=nocona --with-tune=core2 --with-libiconv --with-system-zlib --with-gmp=/c/mingw610/prerequisites/x86_64-w64-mingw32-static --with-mpfr=/c/mingw610/prerequisites/x86_64-w64-mingw32-static --with-mpc=/c/mingw610/prerequisites/x86_64-w64-mingw32-static --with-isl=/c/mingw610/prerequisites/x86_64-w64-mingw32-static --with-pkgversion='x86_64-posix-seh, Built by MinGW-W64 project' --with-bugurl=http://sourceforge.net/projects/mingw-w64 CFLAGS='-O2 -pipe -I/c/mingw610/x86_64-610-posix-seh-rt_v5/mingw64/opt/include -I/c/mingw610/prerequisites/x86_64-zlib-static/include -I/c/mingw610/prerequisites/x86_64-w64-mingw32-static/include' CXXFLAGS='-O2 -pipe -I/c/mingw610/x86_64-610-posix-seh-rt_v5/mingw64/opt/include -I/c/mingw610/prerequisites/x86_64-zlib-static/include -I/c/mingw610/prerequisites/x86_64-w64-mingw32-static/include' CPPFLAGS= LDFLAGS='-pipe -L/c/mingw610/x86_64-610-posix-seh-rt_v5/mingw64/opt/lib -L/c/mingw610/prerequisites/x86_64-zlib-static/lib -L/c/mingw610/prerequisites/x86_64-w64-mingw32-static/lib '
Thread model: posix
gcc version 6.1.0 (x86_64-posix-seh, Built by MinGW-W64 project) 
COLLECT_GCC_OPTIONS='-E' '-P' '-v' '-dD' '-shared-libgcc' '-mtune=core2' '-march=nocona'
 C:/mingw64/bin/../libexec/gcc/x86_64-w64-mingw32/6.1.0/cc1plus.exe -E -quiet -v -P -iprefix C:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/6.1.0/ -D_REENTRANT C:/dev/eclipse-oxy-cpp/.metadata/.plugins/org.eclipse.cdt.managedbuilder.core/spec.C -mtune=core2 -march=nocona -dD
#define __STDC__ 1
#define __cplusplus 201402L
(etc)

以下代码片段可以编译(带有未使用的变量警告,但仍然如此),但 Eclipse 突出显示了在 int main 中解决 test 的问题:

auto test (auto N) {return N;}
int main () {
  auto z = test( 3U );
  return 0;
}

解析器日志给出:

Unresolved names:
   Attempt to use symbol failed: test in file ...

IDE 在问题中显示了这一点:

Invalid arguments '
Candidates are:
? test(?)
'

出于所有意图和目的,eclipse 实际上看到了正确的 gcc 二进制文件,并且使用了正确的 c++ 标准,但根据上述证据仍然不符合编译器(除非我错过了什么?)。

如果 eclipse 已经有了正确的 c++ 标准版本,有什么想法可以让 eclipse 进行语法分析吗?

我觉得这是索引器的问题,而不是解析器的问题,因为它可以轻松计算出参数的数量或声明,但似乎无法理解 auto 的函数return 类型取决于自动输入的参数。

更新

可能与this bug (looks to be fixed) and this followup bug有关(仍在进行中,给出的测试用例与我的相似)。

然而,这个版本的 test 没有给我带来问题,所以我不确定是同一个错误还是其他原因...

template< typename T > auto test (T N) {return N;}

auto 函数的参数类型(相对于 lambda)不是标准的 C++14。

Concepts TS 支持它(GCC >= 6 支持 -fconcepts 标志),即使没有 -fconcepts as 也被 GCC >= 4.9 接受一个扩展,但它不是标准的。 (它可能会成为 C++20 中的标准,连同 Concepts TS 的其他部分。)

例如,以下是 Clang(不支持此扩展)对您在 C++14 模式下的代码的评价:

test.cpp:1:12: error: 'auto' not allowed in function prototype
auto test (auto N) {return N;}
           ^~~~

Eclipse CDT 目前也没有实现这个扩展。我提交了 bug 532085 来跟踪添加对它的支持;欢迎投稿!