summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndy Shaw <andy.shaw@qt.io>2023-02-20 14:47:20 +0100
committerJoerg Bornemann <joerg.bornemann@qt.io>2023-03-28 15:09:16 +0000
commita1b46788b7d2bf0117dbf63f4b4fedbc4a91eeb8 (patch)
tree59d3271b0a0c328a99bd52c04421e7115ed8ab8c
parent34397930803f3d4648b868186cee2e6a593181cd (diff)
downloadqttools-a1b46788b7d2bf0117dbf63f4b4fedbc4a91eeb8.tar.gz
Don't treat enum classes as a normal class
The enum class construct can only be based on an integral type so they can be skipped over safely. Pick-to: 6.5 Task-number: QTBUG-36589 Change-Id: I9a7dd7508f80002e9e46429de726a75607d21a54 Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
-rw-r--r--src/linguist/lupdate/cpp.cpp13
-rw-r--r--tests/auto/linguist/lupdate/testdata/good/parsecpp/main.cpp10
-rw-r--r--tests/auto/linguist/lupdate/testdata/good/parsecpp/project.ts.result8
3 files changed, 30 insertions, 1 deletions
diff --git a/src/linguist/lupdate/cpp.cpp b/src/linguist/lupdate/cpp.cpp
index cc56f2d5d..7779bd99e 100644
--- a/src/linguist/lupdate/cpp.cpp
+++ b/src/linguist/lupdate/cpp.cpp
@@ -98,7 +98,7 @@ private:
};
enum TokenType {
- Tok_Eof, Tok_class, Tok_friend, Tok_namespace, Tok_using, Tok_return,
+ Tok_Eof, Tok_class, Tok_enum, Tok_friend, Tok_namespace, Tok_using, Tok_return,
Tok_Q_OBJECT, Tok_Access, Tok_Cancel,
Tok_Ident, Tok_String, Tok_RawString, Tok_Arrow, Tok_Colon, Tok_ColonColon,
Tok_Equals, Tok_LeftBracket, Tok_RightBracket, Tok_QuestionMark,
@@ -337,6 +337,7 @@ CppParser::TokenType CppParser::lookAheadToSemicolonOrLeftBrace()
static const QString strQ_OBJECT = u"Q_OBJECT"_s;
static const QString strclass = u"class"_s;
+static const QString strenum = u"enum"_s;
static const QString strfinal = u"final"_s;
static const QString strfriend = u"friend"_s;
static const QString strnamespace = u"namespace"_s;
@@ -580,6 +581,10 @@ CppParser::TokenType CppParser::getToken()
if (yyWord == strclass)
return Tok_class;
break;
+ case 'e':
+ if (yyWord == strenum)
+ return Tok_enum;
+ break;
case 'f':
if (yyWord == strfriend)
return Tok_friend;
@@ -2064,6 +2069,12 @@ void CppParser::parseInternal(ConversionData &cd, const QStringList &includeStac
}
yyTok = getToken();
break;
+ case Tok_enum:
+ yyTok = getToken();
+ // If it is an enum class then ignore
+ if (yyTok == Tok_class)
+ yyTok = getToken();
+ break;
default:
if (!yyParenDepth)
prospectiveContext.clear();
diff --git a/tests/auto/linguist/lupdate/testdata/good/parsecpp/main.cpp b/tests/auto/linguist/lupdate/testdata/good/parsecpp/main.cpp
index 43b493203..4af6fc9ba 100644
--- a/tests/auto/linguist/lupdate/testdata/good/parsecpp/main.cpp
+++ b/tests/auto/linguist/lupdate/testdata/good/parsecpp/main.cpp
@@ -718,3 +718,13 @@ class QTBUG110630 : QObject {
tr("translation with extras-quoted field");
}
};
+
+// enum class - C++11
+enum class Bar : unsigned short;
+// QTBUG-36589: Don't treat enum classes as a normal class
+class QTBUG36589 : QObject {
+ Q_OBJECT
+ const QString txt() {
+ tr("string after an enum class");
+ }
+};
diff --git a/tests/auto/linguist/lupdate/testdata/good/parsecpp/project.ts.result b/tests/auto/linguist/lupdate/testdata/good/parsecpp/project.ts.result
index bf3c20877..fe5c00d96 100644
--- a/tests/auto/linguist/lupdate/testdata/good/parsecpp/project.ts.result
+++ b/tests/auto/linguist/lupdate/testdata/good/parsecpp/project.ts.result
@@ -431,6 +431,14 @@ backslashed \ stuff.</source>
</message>
</context>
<context>
+ <name>QTBUG36589</name>
+ <message>
+ <location filename="main.cpp" line="728"/>
+ <source>string after an enum class</source>
+ <translation type="unfinished"></translation>
+ </message>
+</context>
+<context>
<name>QTBUG99415</name>
<message>
<location filename="main.cpp" line="707"/>