In this example:
```
//template<std::same_as<int> T> // <= works
template<same_as<int> T>        // <= didn't work
void f()
{}
```
the changed line used to match to `< same_as <`, therefore skip creating links.
The `%op% %name% <` already feels a bit like a workaround. So adding the condition that $op$ shouldn't be a comparison operator, but part of the template, seemed reasonable to me

Co-authored-by: Gerbo Engels <gerbo.engels@ortec-finance.com>
This commit is contained in:
gerboengels 2022-10-16 19:33:44 +02:00 committed by GitHub
parent 2ac9fbc1bf
commit 221873e69f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 1 deletions

View File

@ -4702,7 +4702,7 @@ void Tokenizer::createLinks2()
} else {
type.pop();
if (Token::Match(token, "> %name%") && !token->next()->isKeyword() &&
Token::Match(top1->tokAt(-2), "%op% %name% <") &&
Token::Match(top1->tokAt(-2), "%op% %name% <") && top1->strAt(-2) != "<" &&
(templateTokens.empty() || top1 != templateTokens.top()))
continue;
Token::createMutualLinks(top1, token);

View File

@ -3250,6 +3250,20 @@ private:
ASSERT(nullptr == Token::findsimplematch(tokenizer.tokens(), "<")->link());
}
{
// #11319
const char code[] = "using std::same_as;\n"
"template<same_as<int> T>\n"
"void f();";
Tokenizer tokenizer(&settings0, this);
std::istringstream istr(code);
ASSERT(tokenizer.tokenize(istr, "test.cpp"));
const Token *tok1 = Token::findsimplematch(tokenizer.tokens(), "template <");
const Token *tok2 = Token ::findsimplematch(tokenizer.tokens(), "same_as <");
ASSERT(tok1->next()->link() == tok1->tokAt(7));
ASSERT(tok2->next()->link() == tok2->tokAt(3));
}
{
// #9131 - template usage or comparison?
const char code[] = "using std::list; list<t *> l;";