Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clang >= 3.3 in c++1y mode cannot parse <cstdio> header

I have a project that correctly compiles and runs under g++ 4.8.1 and clang >= 3.3 in c++11 mode. However, when I switch to the experimental -std=c++1y mode, clang 3.3 (but not g++) chokes on the <cstdio> header that is indirectly included by way of Boost.Test (so I cannot easily change it myself)

// /usr/include/c++/4.8/cstdio #include <stdio.h>  // Get rid of those macros defined in <stdio.h> in lieu of real functions. // ... #undef gets // ...      namespace std { // ... using ::gets; // <-- error with clang++ -std=c++1y // ... } 

with the following error message:

/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../include/c++/4.8/cstdio:119:11: error: no member named 'gets' in the global namespace

On this tutorial on how to set up a modern C++ environment, a similar lookup problem with max_align_t is encountered. The recommendation there is to use a sed script to surround the unknown symbols with #ifdef __clang__ macros, but that seems a fragile approach.

Setup: plain 64-bit Linux Mint 15 with

g++ (Ubuntu 4.8.1-2ubuntu1~13.04) 4.8.1

Ubuntu clang version 3.3-3~raring1 (branches/release_33) (based on LLVM 3.3)

Questions:

  • what is causing this erorr? There is no __clang__ macro anywhere near the code in question, and clang in c++11 mode has no trouble at all.
  • Is it a language problem (does C++14 say something else than C++11 about importing C compatible symbols from the global into the std namespace)?
  • Do I need to change something with my include paths? (I use CMake to automatically select the header paths, and switch modes inside CMakeLists.txt)
  • Does clang have a switch to resolve this?
like image 338
TemplateRex Avatar asked Jul 21 '13 18:07

TemplateRex


1 Answers

This note in the gets manpage looks relevant:

ISO C11 removes the specification of gets() from the C language, and since version 2.16, glibc header files don't expose the function declaration if the _ISOC11_SOURCE feature test macro is defined.

Probably should be

#if !_ISOC11_SOURCE using ::gets; #endif 
like image 195
Ben Voigt Avatar answered Oct 01 '22 09:10

Ben Voigt