Opened 9 months ago

Closed 8 months ago

Last modified 8 months ago

#15915 closed build error (fixed)

clang build error caused by HAVE_TYPE_TRAITS

Reported by: wojdyr Owned by:
Priority: normal Milestone:
Component: build Version: dev-latest
Keywords: Cc:
Blocked By: Blocking:
Patch: no

Description

On Fedora 20 wxWidgets (trunk, i haven't checked 3.0) doesn't build using clang.

The error is

In file included from ../include/wx/wxprec.h:58:
In file included from ../include/wx/wx.h:15:
In file included from ../include/wx/object.h:19:
In file included from ../include/wx/memory.h:15:
In file included from ../include/wx/string.h:46:
In file included from ../include/wx/strvararg.h:25:
In file included from /usr/lib/gcc/x86_64-redhat-linux/4.8.2/../../../../include/c++/4.8.2/type_traits:35:
/usr/lib/gcc/x86_64-redhat-linux/4.8.2/../../../../include/c++/4.8.2/bits/c++0x_warning.h:32:2: error:
      This file requires compiler and library support for the ISO C++ 2011
      standard. This support is currently experimental, and must be enabled with
      the -std=c++11 or -std=gnu++11 compiler options.

The triggered #error is after:
#if __cplusplus < 201103L

This file is included because HAVE_TYPE_TRAITS is defined.
In setup.h HAVE_TYPE_TRAITS is _not_ defined, but then in defs.h:

 #if defined(__has_include)
    #if !defined(HAVE_TYPE_TRAITS) && __has_include(<type_traits>)
        #define HAVE_TYPE_TRAITS
    #endif

After removing the #define above it compiles.
With only two unrelated warnings.

../src/common/stopwatch.cpp:75:11: warning: unused variable
      'MICROSECONDS_PER_MILLISECOND' [-Wunused-const-variable]
const int MICROSECONDS_PER_MILLISECOND = 1000;

../src/gtk/print.cpp:57:21: warning: unused variable 'RAD2DEG'
      [-Wunused-const-variable]
static const double RAD2DEG  = 180.0 / M_PI;

Change History (10)

comment:1 follow-up: Changed 9 months ago by vadz

Is it normal that clang uses g++ header?

In any case, I think that if __has_include(<type_traits>) returns true but you can't actually include it, something is seriously wrong with the compiler installation. It doesn't mean that we shouldn't try to work around it somehow...

comment:2 in reply to: ↑ 1 Changed 9 months ago by wojdyr

Replying to vadz:

Is it normal that clang uses g++ header?

In any case, I think that if __has_include(<type_traits>) returns true but you can't actually include it, something is seriously wrong with the compiler installation.

it's what clang 3.3 (from RPM) on Fedora and OpenSUSE does. I suppose it's similar on other distos.

comment:3 Changed 9 months ago by vadz

OK, looking at my own clang (3.4 under Debian) I see that it uses g++ 4.8 headers too, so apparently this is normal.

But this doesn't really help with fixing it... Not using type traits at all with clang in non-C++-11 mode doesn't look like a good idea, it's nice to have proper support for enums in string formatting code. So we probably need to define some NO_TYPE_TRAITS in configure if we ran the checks and they failed and check for this in the code later... Or does anybody see a better solution?

comment:4 Changed 9 months ago by wojdyr

configure detects traits correctly:

$ grep TRAITS ./lib/wx/include/gtk2-unicode-3.1/wx/setup.h
#define HAVE_TR1_TYPE_TRAITS 1
/* #undef HAVE_TYPE_TRAITS */

The problem is in include/wx/defs.h where macros from setup.h are overwritten.
Maybe just skip it in defs.h if at least one type_traits location is known.
Like this (not tested):

  • include/wx/defs.h

     
    351351#endif 
    352352 
    353353#if defined(__has_include) 
    354     #if !defined(HAVE_TYPE_TRAITS) && __has_include(<type_traits>) 
    355         #define HAVE_TYPE_TRAITS 
     354    #if !defined(HAVE_TYPE_TRAITS) && !defined(HAVE_TR1_TYPE_TRAITS) 
     355        #if __has_include(<type_traits>) 
     356            #define HAVE_TYPE_TRAITS 
     357        #elif __has_include(<tr1/type_traits>) 
     358            #define HAVE_TR1_TYPE_TRAITS 
     359        #endif 
    356360    #endif 
    357361 
    358     #if !defined(HAVE_TR1_TYPE_TRAITS) && __has_include(<tr1/type_traits>) 
    359         #define HAVE_TR1_TYPE_TRAITS 
    360     #endif 
    361  
    362362    #if !defined(HAVE_STD_UNORDERED_MAP) && __has_include(<unordered_map>) 
    363363        #define HAVE_STD_UNORDERED_MAP 
    364364    #endif 

comment:5 Changed 8 months ago by VZ

  • Resolution set to fixed
  • Status changed from new to closed

(In [75983]) Fix Unix build using clang with g++ 4.8 headers.

Don't override HAVE_TR1_TYPE_TRAITS detected by configure with
HAVE_TYPE_TRAITS detected by clang has_include() as the latter is less
reliable and can return true even when the header is not actually usable, as
it happens with g++ 4.8 <type_traits> in non C++11 mode.

Closes #15915.

comment:6 Changed 8 months ago by VZ

(In [75984]) Fix harmless warnings about unused global variables.

Don't define variables that we never use to fix clang warnings about them.

See #15915.

comment:7 Changed 8 months ago by VZ

(In [75985]) Fix Unix build using clang with g++ 4.8 headers.

Don't override HAVE_TR1_TYPE_TRAITS detected by configure with
HAVE_TYPE_TRAITS detected by clang has_include() as the latter is less
reliable and can return true even when the header is not actually usable, as
it happens with g++ 4.8 <type_traits> in non C++11 mode.

Closes #15915.

comment:8 Changed 8 months ago by VZ

(In [75986]) Fix harmless warnings about unused global variables.

Don't define variables that we never use to fix clang warnings about them.

See #15915.

comment:9 Changed 8 months ago by VS

(In [76016]) Fix compilation with Xcode projects (type_traits).

The changes to type_traits headers detection with Clang broke Clang use
with the Xcode projects. Fix this by not setting HAVE_* macros in
config_xcode.h for Clang and letting defs.h detect the features.

See #15915.

comment:10 Changed 8 months ago by VS

(In [76017]) Fix compilation with Xcode projects (type_traits).

The changes to type_traits headers detection with Clang broke Clang use
with the Xcode projects. Fix this by not setting HAVE_* macros in
config_xcode.h for Clang and letting defs.h detect the features.

See #15915.

Note: See TracTickets for help on using tickets.