From a1b46788b7d2bf0117dbf63f4b4fedbc4a91eeb8 Mon Sep 17 00:00:00 2001 From: Andy Shaw Date: Mon, 20 Feb 2023 14:47:20 +0100 Subject: 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 --- src/linguist/lupdate/cpp.cpp | 13 ++++++++++++- tests/auto/linguist/lupdate/testdata/good/parsecpp/main.cpp | 10 ++++++++++ .../lupdate/testdata/good/parsecpp/project.ts.result | 8 ++++++++ 3 files changed, 30 insertions(+), 1 deletion(-) 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 @@ -430,6 +430,14 @@ backslashed \ stuff. string with spaces + + QTBUG36589 + + + string after an enum class + + + QTBUG99415 -- cgit v1.2.1