moc: recover bad template parsing.

When encountering code such as:
  X<a<b>
moc does not have the mean to know if 'a' is a type or a variable, so the
type parser currently assume that '<' always open a template parameter.
(instead of being the operator<)

The type parser do not care about the actual type, it just need to strip
the string out. The problem is that then the whole rest of the file will
be considered as the type.

With this patch, we also stop the parsing at semicolon.  The type will
be wrong, but this allow the parser to recover and it will continue to
look for more classes after this.

(In other words, moc will no longer break if it encounter such construct
in a header. But it will still not parse such types correctly if used
within a Q_OBJECT class)

Task-number: QTBUG-31218

Change-Id: I1fef6bc58493d7c00df72401c9ad55463b24eaa7
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
This commit is contained in:
Olivier Goffart 2013-05-18 11:24:12 +02:00 committed by The Qt Project
parent f1d1b8219c
commit 208e9a2757
2 changed files with 8 additions and 0 deletions

View File

@ -1449,6 +1449,11 @@ bool Moc::until(Token target) {
--index;
break;
}
if (braceCount <= 0 && t == SEMIC) {
// Abort on semicolon. Allow recovering bad template parsing (QTBUG-31218)
break;
}
}
if(target == COMMA && angleCount != 0 && possible != -1) {

View File

@ -79,6 +79,9 @@
QT_USE_NAMESPACE
template <bool b> struct QTBUG_31218 {};
struct QTBUG_31218_Derived : QTBUG_31218<-1<0> {};
struct MyStruct {};
struct MyStruct2 {};