summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Hanselmann <public@hansmi.ch>2015-12-17 13:26:46 +0100
committerMichael Hanselmann <public@hansmi.ch>2016-01-05 16:20:20 +0000
commit00c523ab372c680984b17ad8d66939cd3aaa8f34 (patch)
treeb20a405bdbc50dc911daaff9bc3d977acba9c324
parentbdd4e502ffd81084f33181426df31ffcddde637c (diff)
lupdate: Support for C++11's "final" identifier
C++11 introduced the "final" identifier which may appear immediately after the name in a class definition to specify that the class cannot be derived from. lupdate collects strings for translation and did not understand "final". Instead it would use "final" as the name of the class as there may be attributes before the class name and the last token before the colon character is used. [ChangeLog][lupdate] The C++11 identifier "final" is now skipped when determining the name of a class. Task-number: QTBUG-42735 Change-Id: I2adee9a188645622fc6916158ba2b48dde921383 Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@theqtcompany.com>
-rw-r--r--src/linguist/lupdate/cpp.cpp7
-rw-r--r--tests/auto/linguist/lupdate/testdata/good/parsecpp/main.cpp37
-rw-r--r--tests/auto/linguist/lupdate/testdata/good/parsecpp/project.ts.result21
3 files changed, 65 insertions, 0 deletions
diff --git a/src/linguist/lupdate/cpp.cpp b/src/linguist/lupdate/cpp.cpp
index 9acae45aa..963e5c53f 100644
--- a/src/linguist/lupdate/cpp.cpp
+++ b/src/linguist/lupdate/cpp.cpp
@@ -456,6 +456,7 @@ int CppParser::getChar()
STRING(Q_OBJECT);
STRING(class);
+STRING(final);
STRING(friend);
STRING(namespace);
STRING(operator);
@@ -1817,6 +1818,12 @@ void CppParser::parseInternal(ConversionData &cd, const QStringList &includeStac
quali << fct;
yyTok = getToken();
} else if (yyTok == Tok_Ident) {
+ if (yyWord == strfinal) {
+ // C++11: final may appear immediately after the name of the class
+ yyTok = getToken();
+ break;
+ }
+
// Handle impure definitions such as 'class Q_EXPORT QMessageBox', in
// which case 'QMessageBox' is the class name, not 'Q_EXPORT', by
// abandoning any qualification collected so far.
diff --git a/tests/auto/linguist/lupdate/testdata/good/parsecpp/main.cpp b/tests/auto/linguist/lupdate/testdata/good/parsecpp/main.cpp
index 8b91a7761..6be775994 100644
--- a/tests/auto/linguist/lupdate/testdata/good/parsecpp/main.cpp
+++ b/tests/auto/linguist/lupdate/testdata/good/parsecpp/main.cpp
@@ -410,3 +410,40 @@ int dupeFail()
// Finally, same source, but without ID.
QCoreApplication::translate("", "This is the source");
}
+
+
+
+// QTBUG-42735: lupdate confused by `final` specifier (C++11)
+namespace Abc {
+
+class NamespacedFinalClass;
+
+}
+
+class FinalClass final : public QObject
+{
+ Q_OBJECT
+
+ class SubClass final
+ {
+ void f()
+ {
+ tr("nested class context with final");
+ }
+ };
+
+ void f()
+ {
+ tr("class context with final");
+ }
+};
+
+class Abc::NamespacedFinalClass final : public QObject
+{
+ Q_OBJECT
+
+ void f()
+ {
+ tr("namespaced class with final");
+ }
+};
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 0c0c1b511..be393f9d7 100644
--- a/tests/auto/linguist/lupdate/testdata/good/parsecpp/project.ts.result
+++ b/tests/auto/linguist/lupdate/testdata/good/parsecpp/project.ts.result
@@ -33,6 +33,14 @@ backslashed \ stuff.</source>
</message>
</context>
<context>
+ <name>Abc::NamespacedFinalClass</name>
+ <message>
+ <location filename="main.cpp" line="447"/>
+ <source>namespaced class with final</source>
+ <translation type="unfinished"></translation>
+ </message>
+</context>
+<context>
<name>Bogus</name>
<message>
<location filename="main.cpp" line="258"/>
@@ -117,6 +125,19 @@ backslashed \ stuff.</source>
</message>
</context>
<context>
+ <name>FinalClass</name>
+ <message>
+ <location filename="main.cpp" line="431"/>
+ <source>nested class context with final</source>
+ <translation type="unfinished"></translation>
+ </message>
+ <message>
+ <location filename="main.cpp" line="437"/>
+ <source>class context with final</source>
+ <translation type="unfinished"></translation>
+ </message>
+</context>
+<context>
<name>FindDialog</name>
<message>
<location filename="finddialog.cpp" line="77"/>