Commit e3883a89 authored by Milian Wolff's avatar Milian Wolff

Don't get confused when encountering parse errors in default args

When we fail to get a useful string for a default arg, show at least
an explanatory "<parse error>" string in its place.

Sadly, it's not trivial to get the raw string in this case. Doable
maybe, but requires more manual work since the cursor extent won't
include e.g. a mistyped macro name or such.

CCBUG: 369546
parent 54585bcd
Pipeline #13558 passed with stage
in 48 minutes and 50 seconds
......@@ -25,3 +25,12 @@ namespace dr373 { // dr373: no
}
};
}
#define BAR 2
/// "internalContext" : { "localDeclarationCount" : 4, "findDeclarations" : {
/// "sure" : { "defaultParameter" : "nullptr" },
/// "a" : { "defaultParameter" : "<parse error>" },
/// "b" : { "defaultParameter" : "BAR" },
/// "c" : { "defaultParameter" : "3" }
/// } }
int asdf(int *sure = nullptr, int a = NOT_DEFINED, int b = BAR, int c = 3);
......@@ -178,6 +178,8 @@ QVector<QString> ClangUtils::getDefaultArguments(CXCursor cursor, DefaultArgumen
info.stringParts.clear();
clang_visitChildren(arg, paramVisitor, &info);
const auto hasDefault = !info.stringParts.isEmpty();
//Clang includes the equal sign sometimes, but not other times.
if (!info.stringParts.isEmpty() && info.stringParts.first() == QLatin1String("=")) {
info.stringParts.removeFirst();
......@@ -196,6 +198,12 @@ QVector<QString> ClangUtils::getDefaultArguments(CXCursor cursor, DefaultArgumen
arguments.replace(i, result);
} else if (!result.isEmpty()) {
arguments << result;
} else if (hasDefault) {
// no string obtained, probably due to a parse error...
// we have to include some argument, otherwise it's even more confusing to our users
// furthermore, we cannot even do getRawContents on the arg's cursor, as it's cursor
// extent stops at the first error...
arguments << i18n("<parse error>");
}
}
return arguments;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment