Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rtags-flycheck doesn't use the correct c++ standard, aka c++14 #1095

Closed
1 of 7 tasks
amosbird opened this issue Nov 16, 2017 · 11 comments
Closed
1 of 7 tasks

rtags-flycheck doesn't use the correct c++ standard, aka c++14 #1095

amosbird opened this issue Nov 16, 2017 · 11 comments

Comments

@amosbird
Copy link

Please mark appropriate

  • rtags (rdm/rc/rp)
  • Emacs Lisp
    • ac-rtags.el
    • company-rtags.el
    • helm-rtags.el
    • flycheck-rtags.el
    • ivy-rtags.el
    • rtags.el

Problem description

rtags-flycheck warns std::enable_if_t isn't declared, which should be fine in c++14.

Environment

  • Your operating system:
    Centos 7
  • LLVM/Clang version:
    clang 4.0
@amosbird
Copy link
Author

amosbird commented Nov 17, 2017

Hmm, this becomes more subtle.

/home/amos/git/ClickHouse/dbms/src/DataStreams/InputStreamFromASTInsertQuery.cpp:22:29: error: Semantic Issue: no member named 'make_unique' in namespace 'std'

Can I make rtags use -std=gnu++1z ?

And how can I jump to the error position (row, column) instead of just row ?

@collinjackson93
Copy link
Contributor

Can you paste one of the commands from your compilation database? I believe rtags simply forwards those commands (which should have the standard version listed) to clang, which then finds any errors.

@amosbird
Copy link
Author

sure

{
  "directory": "/home/amos/git/ClickHouse/dbg",
  "command": "/usr/local/bin/clang++  -DBOOST_SYSTEM_NO_DEPRECATED -DLZ4_DISABLE_DEPRECATE_WARNINGS=1 -DPOCO_UNBUNDLED_ZLIB -I../libs/libdaemon/include -I../contrib/libunwind/include -Icontrib/libunwind/config -I../dbms/src -Idbms/src -I../contrib/libpcg-random/include -I../contrib/libcityhash/include -I../libs/libcommon/include -Ilibs/libcommon/include -I../libs/libpocoext/include -I../contrib/poco/Util/include -I../contrib/poco/Foundation/include -I../contrib/libzlib-ng -Icontrib/libzlib-ng -I../contrib/poco/XML/include -I../contrib/poco/JSON/include -I../contrib/poco/Net/include -I../contrib/cctz/include -I../contrib/libboost/boost_1_65_0 -I../contrib/libtcmalloc/include -Icontrib/libfarmhash -I../contrib/lz4/lib -I../contrib/zstd/lib -I../contrib/zookeeper/src/c/include -Icontrib/zookeeper/src/c/include -I../contrib/zookeeper/src/c/generated -I../contrib/libdouble-conversion/. -I../contrib/libcpuid/include -I../contrib/libre2/. -Icontrib/libre2 -I../contrib/poco/Data/include -I../contrib/libbtrie/include -I../contrib/poco/Data/ODBC/include -I../contrib/poco/MongoDB/include -I../contrib/poco/NetSSL_OpenSSL/include -I../contrib/poco/Crypto/include -I../contrib/librdkafka/src -Icontrib/librdkafka/generated/dummy -I../contrib/libdivide -I../contrib/libmetrohash/src -I../contrib/libfarmhash    -D_GLIBCXX_USE_CXX11_ABI=1 -pipe -msse4.1 -msse4.2 -mpopcnt  -fno-omit-frame-pointer -Wall -Wnon-virtual-dtor  -Werror -g -O0 -g3 -ggdb3 -fno-inline -fPIC   -DNO_TCMALLOC_SAMPLES -DNDEBUG -DNO_FRAME_POINTER -Wwrite-strings -Wno-sign-compare -Wno-unused-result -Wno-deprecated-declarations -Wno-unused-function -Wno-unused-private-field -fno-builtin-malloc -fno-builtin-free -fno-builtin-realloc -fno-builtin-calloc -fno-builtin-cfree -fno-builtin-memalign -fno-builtin-posix_memalign -fno-builtin-valloc -fno-builtin-pvalloc -Wno-dynamic-exception-spec -std=gnu++1z -o dbms/src/Server/CMakeFiles/clickhouse-server.dir/Server.cpp.o -c /home/amos/git/ClickHouse/dbms/src/Server/Server.cpp",
  "file": "/home/amos/git/ClickHouse/dbms/src/Server/Server.cpp"
},

@collinjackson93
Copy link
Contributor

According to this gnu++1z is deprecated. Can you try changing it to gnu++17 or c++17 and see if you get the same behavior? My guess is that clang defaults to c++11 when no std flag is passed or it gets one it can't interpret.

@amosbird
Copy link
Author

@collinjackson93 hi, sadly it still doesn't work.

@collinjackson93
Copy link
Contributor

I attempted to reproduce on my system, but had issues getting everything set up to build ClickHouse.

I just noticed that you're using Clang 4.0, which doesn't have full support for C++17. As a test, can you try using -std=c++14?

If that doesn't work, we should be able to quickly put together a small test program that calls std::make_unique to make it easier to reproduce so I can attempt it on my system (which is running Clang 5.0).

@amosbird
Copy link
Author

OK, I've setup a clang-5 env. rdm shows this error when parsing certain source file.

rp: /home/amos/git/build-llvm/llvm-5.0.0/llvm-5.0.0.src/tools/clang/lib/Sema/SemaDecl.cpp:1268: void clang::Sema::EnterDeclaratorContext(clang::Scope*, clang::DeclContext*): Assertion `Ancestor->getEntity() == CurContext && "ancestor context mismatch"' failed.
libclang: crash detected during parsing: {
  'source_filename' : '/home/amos/git/ClickHouse/contrib/poco/Foundation/src/DateTimeFormat.cpp'
  'command_line_args' : ['clang', '-pipe', '-msse4.1', '-msse4.2', '-mpopcnt', '-fno-omit-frame-pointer', '-Wall', '-Wnon-virtual-dtor', '-Wno-old-style-cast', '-g', '-O0', '-g3', '-ggdb3', '-fno-inline', '-fPIC', '-Wno-sign-compare', '-Wno-non-virtual-dtor', '-fno-strict-aliasing', '-Wno-unknown-pragmas', '-std=gnu++1z', '-c', '-ferror-limit=50', '-Wall', '-fspell-checking', '-Wno-unknown-warning-option', '-DRTAGS=', '-D_FILE_OFFSET_BITS=64', '-D_GLIBCXX_USE_CXX11_ABI=1', '-D_XOPEN_SOURCE=500', '-DFoundation_EXPORTS', '-DHAVE_PTHREAD_SETAFFINITY_NP', '-DHAVE_THREE_PARAM_SCHED_SETAFFINITY', '-DPCRE_STATIC', '-DPOCO_EXTERNAL_OPENSSL', '-DPOCO_HAVE_FD_EPOLL', '-DPOCO_UNBUNDLED', '-DPOCO_UNBUNDLED_ZLIB', '-D_DEBUG', '-D_LARGEFILE64_SOURCE', '-D_REENTRANT', '-D_THREAD_SAFE', '-I/home/amos/git/ClickHouse/dbg/../contrib/poco/Foundation/include', '-I/home/amos/git/ClickHouse/dbg/../contrib/poco/Foundation/src', '-I/home/amos/git/ClickHouse/dbg/../contrib/libzlib-ng', '-I/home/amos/git/ClickHouse/dbg/contrib/libzlib-ng'],
  'unsaved_files' : [],
  'options' : 513,
}
Failed to parse clang "-pipe" "-msse4.1" "-msse4.2" "-mpopcnt" "-fno-omit-frame-pointer" "-Wall" "-Wnon-virtual-dtor" "-Wno-old-style-cast" "-g" "-O0" "-g3" "-ggdb3" "-fno-inline" "-fPIC" "-Wno-sign-compare" "-Wno-non-virtual-dtor" "-fno-strict-aliasing" "-Wno-unknown-pragmas" "-std=gnu++1z" "-c" "-ferror-limit=50" "-Wall" "-fspell-checking" "-Wno-unknown-warning-option" "-DRTAGS=" "-D_FILE_OFFSET_BITS=64" "-D_GLIBCXX_USE_CXX11_ABI=1" "-D_XOPEN_SOURCE=500" "-DFoundation_EXPORTS" "-DHAVE_PTHREAD_SETAFFINITY_NP" "-DHAVE_THREE_PARAM_SCHED_SETAFFINITY" "-DPCRE_STATIC" "-DPOCO_EXTERNAL_OPENSSL" "-DPOCO_HAVE_FD_EPOLL" "-DPOCO_UNBUNDLED" "-DPOCO_UNBUNDLED_ZLIB" "-D_DEBUG" "-D_LARGEFILE64_SOURCE" "-D_REENTRANT" "-D_THREAD_SAFE" "-I/home/amos/git/ClickHouse/dbg/../contrib/poco/Foundation/include" "-I/home/amos/git/ClickHouse/dbg/../contrib/poco/Foundation/src" "-I/home/amos/git/ClickHouse/dbg/../contrib/libzlib-ng" "-I/home/amos/git/ClickHouse/dbg/contrib/libzlib-ng" /home/amos/git/ClickHouse/contrib/poco/Foundation/src/DateTimeFormat.cpp

@collinjackson93
Copy link
Contributor

That looks like an error from libclang itself, not rtags. I wonder if that assertion started failing in clang 5 or if you just got lucky with clang 4. You might want to report that to llvm.

As for your initial problem with c++14 support, can you try compiling the following simple program using clang++ -std=gnu++1z?

#include <memory>
#include <iostream>

int main()
{
  auto a = std::make_unique<int>(10);
  std::cout << *a << std::endl;
  return 0;
}

If you can, I would try compiling with clang 4 since you ran into a different error with clang 5.

I was unable to compile it on one of my computers running clang 5 (most likely because the libc++ version is too old), however, it compiled successfully on my other computer (also running clang 5).

If it compiles using clang, try running it through rtags. I did rc -c clang++ -std=gnu++1z makeUnique.cpp followed by rc --diagnose makeUnique.cpp. The rc documentation is a little hard to follow, but I think --diagnose is the one that runs diagnostics on the file (which is what rtags-flycheck displays).

@amosbird
Copy link
Author

As for your initial problem with c++14 support, can you try compiling the following simple program using clang++ -std=gnu++1z?

It compiles.

If you can, I would try compiling with clang 4 since you ran into a different error with clang 5.

It also works.

If it compiles using clang, try running it through rtags.

Hmm, i got nothing after running rc -c clang++ -std=gnu++1z makeUnique.cpp. It exists with return code 1. And rc --diagnose makeUnique.cpp says the file isn't indexed.

@amosbird
Copy link
Author

I even tried https://github.com/llvm-project/llvm-project-20170507 from which rtags still cannot parse clickhouse correctly.

@amosbird
Copy link
Author

OK, I resolved this by following steps,

  1. get clang's include path via clang++ -v -xc++ /dev/null -fsyntax-only. Mine is
 /usr/local/bin/../lib/gcc/x86_64-pc-linux-gnu/7.2.0/../../../../include/c++/7.2.0
 /usr/local/bin/../lib/gcc/x86_64-pc-linux-gnu/7.2.0/../../../../include/c++/7.2.0/x86_64-pc-linux-gnu
 /usr/local/bin/../lib/gcc/x86_64-pc-linux-gnu/7.2.0/../../../../include/c++/7.2.0/backward
 /usr/local/include
 /usr/local/lib/clang/6.0.0/include
 /usr/include
  1. Add those paths into $HOME/.rdmrc like this
-I/usr/local/bin/../lib/gcc/x86_64-pc-linux-gnu/7.2.0/../../../../include/c++/7.2.0
-I/usr/local/bin/../lib/gcc/x86_64-pc-linux-gnu/7.2.0/../../../../include/c++/7.2.0/x86_64-pc-linux-gnu
-I/usr/local/bin/../lib/gcc/x86_64-pc-linux-gnu/7.2.0/../../../../include/c++/7.2.0/backward
-I/usr/local/include
-I/usr/local/lib/clang/6.0.0/include
-I/usr/include
  1. remove rtags cache files rm -rf $HOME/.cache/rtags and reindex target project.

Hope it help. Cheers!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants