Make CONFIG += c++11 by default not disable GNU extensions

Prefer -std=gnu++11 unless strict_c++11 is defined. You can enable
strict C++11/C++14 mode by using
   CONFIG += strict_c++

That is enabled for Qt's own code, so we we don't accidentally use GNU
extensions in portable code.

There's no support for strict C++98 mode (that is, the -ansi option).

[ChangeLog][qmake] By default, GNU extensions are now enabled with
Clang, GCC and ICC even in C++11 and C++14 modes. To disable the GNU
extensions, add to your .pro file: CONFIG += strict_c++.

Change-Id: Ib056b47dde3341ef9a52ffff13ef14de2169bef5
Reviewed-by: Kai Koehne <kai.koehne@theqtcompany.com>
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@theqtcompany.com>
This commit is contained in:
Thiago Macieira 2015-07-08 14:09:10 -07:00
parent 85ff351266
commit ff44440651
11 changed files with 32 additions and 13 deletions

View File

@ -7,4 +7,6 @@ QMAKE_OBJCXXFLAGS_USE_PRECOMPILE = $$QMAKE_CFLAGS_USE_PRECOMPILE
QMAKE_XCODE_GCC_VERSION = com.apple.compilers.llvm.clang.1_0
QMAKE_CXXFLAGS_CXX11 += -stdlib=libc++
QMAKE_CXXFLAGS_GNUCXX11 += -stdlib=libc++
QMAKE_LFLAGS_CXX11 += -stdlib=libc++
QMAKE_LFLAGS_GNUCXX11+= -stdlib=libc++

View File

@ -27,6 +27,7 @@ QMAKE_CXXFLAGS_USE_PRECOMPILE = $$QMAKE_CFLAGS_USE_PRECOMPILE
QMAKE_CXXFLAGS_LTCG = $$QMAKE_CFLAGS_LTCG
QMAKE_CXXFLAGS_DISABLE_LTCG = $$QMAKE_CFLAGS_DISABLE_LTCG
QMAKE_CXXFLAGS_CXX11 = -std=c++11
QMAKE_CXXFLAGS_GNUCXX11 = -std=gnu++11
QMAKE_LFLAGS_CXX11 =
QMAKE_LFLAGS_LTCG = $$QMAKE_CFLAGS_LTCG

View File

@ -28,4 +28,5 @@ QMAKE_CXXFLAGS_PRECOMPILE = -x c++-header -c ${QMAKE_PCH_INPUT} -o ${QMAKE_P
QMAKE_CXXFLAGS_USE_PRECOMPILE = $$QMAKE_CFLAGS_USE_PRECOMPILE
QMAKE_CXXFLAGS_CXX11 = -std=c++0x
QMAKE_CXXFLAGS_GNUCXX11 = -std=gnu++0x
QMAKE_LFLAGS_CXX11 =

View File

@ -1,6 +1,12 @@
strict_c++|isEmpty(QMAKE_CXXFLAGS_GNUCXX11) {
QMAKE_CXXFLAGS += $$QMAKE_CXXFLAGS_CXX11
QMAKE_OBJECTIVE_CFLAGS += $$QMAKE_CXXFLAGS_CXX11
QMAKE_LFLAGS += $$QMAKE_LFLAGS_CXX11
} else {
QMAKE_CXXFLAGS += $$QMAKE_CXXFLAGS_GNUCXX11
QMAKE_OBJECTIVE_CFLAGS += $$QMAKE_CXXFLAGS_GNUCXX11
QMAKE_LFLAGS += $$QMAKE_LFLAGS_GNUCXX11
}
contains(QMAKE_LFLAGS, -stdlib=libc++) {
equals(QMAKE_MACOSX_DEPLOYMENT_TARGET, 10.6): \

View File

@ -2,15 +2,21 @@ intel_icc {
# ICC does not support C++14 yet
} else: clang {
# Clang has supported -std=c++1y since version 3.2
greaterThan(QT_CLANG_MAJOR_VERSION, 3)|greaterThan(QT_CLANG_MINOR_VERSION, 1): \
greaterThan(QT_CLANG_MAJOR_VERSION, 3)|greaterThan(QT_CLANG_MINOR_VERSION, 1) {
QMAKE_CXXFLAGS_CXX11 = -std=c++1y
QMAKE_CXXFLAGS_GNUCXX11 = -std=gnu++1y
}
# Unknown how long Apple Clang has supported -std=c++1y, but at least since XCode 5.0
greaterThan(QT_APPLE_CLANG_MAJOR_VERSION, 4): \
greaterThan(QT_APPLE_CLANG_MAJOR_VERSION, 4) {
QMAKE_CXXFLAGS_CXX11 = -std=c++1y
QMAKE_CXXFLAGS_GNUCXX11 = -std=gnu++1y
}
} else: gcc {
# GCC has supported -std=c++1y since 4.8
greaterThan(QT_GCC_MAJOR_VERSION, 4)|greaterThan(QT_GCC_MINOR_VERSION, 7): \
greaterThan(QT_GCC_MAJOR_VERSION, 4)|greaterThan(QT_GCC_MINOR_VERSION, 7) {
QMAKE_CXXFLAGS_CXX11 = -std=c++1y
QMAKE_CXXFLAGS_GNUCXX11 = -std=gnu++1y
}
}
# Delegate to c++11.prf

View File

@ -12,7 +12,7 @@
QMAKE_DIR_REPLACE_SANE += DESTDIR
CONFIG -= debug_and_release_target
contains(QT_CONFIG, c++11): CONFIG += c++11
contains(QT_CONFIG, c++11): CONFIG += c++11 strict_c++
contains(TEMPLATE, .*lib) {
# module and plugins
!host_build:contains(QT_CONFIG, reduce_exports): CONFIG += hide_symbols

View File

@ -50,6 +50,7 @@ QMAKE_CXXFLAGS_SPLIT_SECTIONS = $$QMAKE_CFLAGS_SPLIT_SECTIONS
# Disabling exceptions disabled - workaround for QTBUG-36577
#QMAKE_CXXFLAGS_EXCEPTIONS_OFF = -fno-exceptions
QMAKE_CXXFLAGS_CXX11 = -std=c++0x
QMAKE_CXXFLAGS_GNUCXX11 = -std=gnu++0x
QMAKE_CXXFLAGS_LTCG = $$QMAKE_CFLAGS_LTCG
QMAKE_INCDIR =

View File

@ -53,6 +53,7 @@ QMAKE_CXXFLAGS_STATIC_LIB = $$QMAKE_CFLAGS_STATIC_LIB
QMAKE_CXXFLAGS_YACC = $$QMAKE_CFLAGS_YACC
QMAKE_CXXFLAGS_THREAD = $$QMAKE_CFLAGS_THREAD
QMAKE_CXXFLAGS_CXX11 = -std=c++11
QMAKE_CXXFLAGS_GNUCXX11 = -std=gnu++11
QMAKE_CXXFLAGS_SPLIT_SECTIONS = $$QMAKE_CFLAGS_SPLIT_SECTIONS
QMAKE_CXXFLAGS_LTCG = $$QMAKE_CFLAGS_LTCG

View File

@ -56,6 +56,7 @@ QMAKE_CXXFLAGS_RTTI_OFF = -fno-rtti
QMAKE_CXXFLAGS_EXCEPTIONS_ON = -fexceptions -mthreads
QMAKE_CXXFLAGS_EXCEPTIONS_OFF = -fno-exceptions
QMAKE_CXXFLAGS_CXX11 = -std=c++0x
QMAKE_CXXFLAGS_GNUCXX11 = -std=gnu++0x
QMAKE_CXXFLAGS_SPLIT_SECTIONS = $$QMAKE_CFLAGS_SPLIT_SECTIONS
QMAKE_INCDIR =

View File

@ -13,9 +13,6 @@ irix-cc*:QMAKE_CXXFLAGS += -no_prelink -ptused
CONFIG += optimize_full
# otherwise mingw headers do not declare common functions like putenv
mingw:QMAKE_CXXFLAGS_CXX11 = -std=gnu++0x
QMAKE_DOCS = $$PWD/doc/qtcore.qdocconf
ANDROID_JAR_DEPENDENCIES = \
@ -48,6 +45,9 @@ include(statemachine/statemachine.pri)
include(mimetypes/mimetypes.pri)
include(xml/xml.pri)
# otherwise mingw headers do not declare common functions like putenv
mingw: CONFIG -= strict_c++
mac|darwin {
!ios {
LIBS_PRIVATE += -framework ApplicationServices

View File

@ -4,9 +4,6 @@ TARGET = QtBootstrap
QT =
CONFIG += internal_module force_bootstrap
# otherwise mingw headers do not declare common functions like putenv
mingw:QMAKE_CXXFLAGS_CXX11 = -std=gnu++0x
MODULE_DEFINES = \
QT_BOOTSTRAPPED \
QT_LITE_UNICODE \
@ -49,6 +46,9 @@ QMAKE_SYNCQT_OPTIONS += -version $$QT_VERSION
load(qt_module)
# otherwise mingw headers do not declare common functions like putenv
mingw: CONFIG -= strict_c++
SOURCES += \
../../corelib/codecs/qlatincodec.cpp \
../../corelib/codecs/qtextcodec.cpp \