[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [kdevelop/5.0] languages/plugins/custom-definesandincludes/compilerprovider: Correctly
From: Alex Richardson <arichardson.kde () gmail ! com>
Date: 2016-03-31 19:30:37
Message-ID: E1aliIf-00023q-Js () scm ! kde ! org
[Download RAW message or body]
Git commit 52346836e143e0fec064092993252d6d51679263 by Alex Richardson.
Committed on 31/03/2016 at 19:30.
Pushed by arichardson into branch '5.0'.
Correctly determine language for more -std= flags
In particular we now support e.g. gnu++1z for C++ as well as gnu99 or
iso9899:1999 and similar for C. This means that the -imacros file will
no longer define __cplusplus when parsing C code.
We also print a warning message now we couldn't determine the language
from the -std= flag
Test Plan:
My files that are compiled with -std==iso9899:1999 show errors about
nullptr not being known. This happened before because __cplusplus was
defined and NULL was therefore defined to nullptr
Reviewers: mwolff, kfunk
Reviewed By: kfunk
Subscribers: kdevelop-devel
Differential Revision: https://phabricator.kde.org/D1277
M +30 -4 languages/plugins/custom-definesandincludes/compilerprovider/gcclikecompiler.cpp
http://commits.kde.org/kdevelop/52346836e143e0fec064092993252d6d51679263
diff --git a/languages/plugins/custom-definesandincludes/compilerprovider/gcclikecompiler.cpp \
b/languages/plugins/custom-definesandincludes/compilerprovider/gcclikecompiler.cpp \
index 525700c..bf8784c 100644
--- a/languages/plugins/custom-definesandincludes/compilerprovider/gcclikecompiler.cpp
+++ b/languages/plugins/custom-definesandincludes/compilerprovider/gcclikecompiler.cpp
@@ -34,18 +34,43 @@ using namespace KDevelop;
namespace
{
+// compilers don't deduplicate QStringLiteral
+QString minusXC() { return QStringLiteral("-xc"); }
+QString minusXCPlusPlus() { return QStringLiteral("-xc++"); }
+
QStringList languageOptions(const QString& arguments)
{
- const QRegularExpression regexp("-std=(c|c\\+\\+)[0-9]{2}");
+ // TODO: handle -ansi flag: In C mode, this is equivalent to -std=c90. In C++ \
mode, it is equivalent to -std=c++98. + // TODO: check for -x flag on command line
+ const QRegularExpression regexp("-std=(\\S+)");
+ // see gcc manpage or llvm/tools/clang/include/clang/Frontend/LangStandards.def \
for list of valid language options auto result = regexp.match(arguments);
if(result.hasMatch()){
auto standard = result.captured(0);
- auto language = result.captured(1) == QStringLiteral("c++") ? \
QStringLiteral("-xc++") : QStringLiteral("-xc"); + QString mode = \
result.captured(1); + QString language;
+ if (mode.startsWith(QLatin1String("c++")) || \
mode.startsWith(QLatin1String("gnu++"))) { + language = minusXCPlusPlus();
+ } else if (mode.startsWith(QLatin1String("iso9899:"))) {
+ // all iso9899:xxxxx modes are C standards
+ language = minusXC();
+ } else {
+ // check for c11, gnu99, etc: all of them have a digit after the c/gnu
+ const QRegularExpression cRegexp("(c|gnu)\\d.*");
+ if (cRegexp.match(mode).hasMatch()) {
+ language = minusXC();
+ }
+ }
+ if (language.isEmpty()) {
+ qCWarning(DEFINESANDINCLUDES) << "Failed to determine language from \
-std= flag:" << arguments; + language = minusXCPlusPlus();
+ }
return {standard, language};
- }
- return {QStringLiteral("--std=c++11"), QStringLiteral("-xc++")};
+ }
+ // no -std= flag passed -> assume c++11
+ return {QStringLiteral("-std=c++11"), minusXCPlusPlus()};
}
}
@@ -63,6 +88,7 @@ Defines GccLikeCompiler::defines(const QString& arguments) const
QProcess proc;
proc.setProcessChannelMode( QProcess::MergedChannels );
+ // TODO: what about -mXXX or -target= flags, some of these change search \
paths/defines auto compilerArguments = languageOptions(arguments);
compilerArguments.append("-dM");
compilerArguments.append("-E");
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic