Программы на C++. Форум разработчиков
Anonymous
Как мне сопоставить встроенные -> использование?
Сообщение
Anonymous » 17 фев 2025, 17:22
Возьмите этот глупый исходный файл c ++: < /p>
Код: Выделить всё
#include
struct Foo {
int hello() const;
};
struct P1 {
P1* another() const;
int give() const;
};
auto fun() {
return std::make_optional(std::make_optional(Foo{}));
}
int main()
{
int * x = new int{3};
P1 * p{};
(*p->another()).another()->another();
p->another()->give();
p->give();
return *x + (*fun())->hello() + p->give();
}
< /code>
Если я выполняю следующую команду на ней, < /p>
clang-query -c "match expr(
anyOf(
unaryOperator(
hasOperatorName(\"*\")
),
unaryOperator(
hasOperatorName(\"->\")
),
cxxOperatorCallExpr(
hasOverloadedOperatorName(\"*\")
),
cxxOperatorCallExpr(
hasOverloadedOperatorName(\"->\")
)
), isExpansionInMainFile()
)" debugging.cpp | less
< /code>
Я получаю выход, который заканчивается, как это (я отфильтровал все совпадения, происходящие в включенных заголовках): < /p>
/home/enrico/debugging.cpp:20:6: note: "root" binds here
20 | (*p->another()).another()->another();
| ^~~~~~~~~~~~~
Match #55:
/home/enrico/debugging.cpp:23:12: note: "root" binds here
23 | return *x + (*fun())->hello() + p->give();
| ^~
Match #56:
/home/enrico/debugging.cpp:23:17: note: "root" binds here
23 | return *x + (*fun())->hello() + p->give();
| ^~~~~~~~~~
Match #57:
/home/enrico/debugging.cpp:23:18: note: "root" binds here
23 | return *x + (*fun())->hello() + p->give();
| ^~~~~~
57 matches.
, который показывает, что встроенный-> не соответствовал, тогда как встроенные и перегруженные * s были сопоставлены.
Что я делаю не так? < /p>
Подробнее здесь:
https://stackoverflow.com/questions/794 ... tin-usages
1739802137
Anonymous
Возьмите этот глупый исходный файл c ++: < /p> [code]#include struct Foo { int hello() const; }; struct P1 { P1* another() const; int give() const; }; auto fun() { return std::make_optional(std::make_optional(Foo{})); } int main() { int * x = new int{3}; P1 * p{}; (*p->another()).another()->another(); p->another()->give(); p->give(); return *x + (*fun())->hello() + p->give(); } < /code> Если я выполняю следующую команду на ней, < /p> clang-query -c "match expr( anyOf( unaryOperator( hasOperatorName(\"*\") ), unaryOperator( hasOperatorName(\"->\") ), cxxOperatorCallExpr( hasOverloadedOperatorName(\"*\") ), cxxOperatorCallExpr( hasOverloadedOperatorName(\"->\") ) ), isExpansionInMainFile() )" debugging.cpp | less < /code> Я получаю выход, который заканчивается, как это (я отфильтровал все совпадения, происходящие в включенных заголовках): < /p> /home/enrico/debugging.cpp:20:6: note: "root" binds here 20 | (*p->another()).another()->another(); | ^~~~~~~~~~~~~ Match #55: /home/enrico/debugging.cpp:23:12: note: "root" binds here 23 | return *x + (*fun())->hello() + p->give(); | ^~ Match #56: /home/enrico/debugging.cpp:23:17: note: "root" binds here 23 | return *x + (*fun())->hello() + p->give(); | ^~~~~~~~~~ Match #57: /home/enrico/debugging.cpp:23:18: note: "root" binds here 23 | return *x + (*fun())->hello() + p->give(); | ^~~~~~ 57 matches. [/code] , который показывает, что встроенный-> не соответствовал, тогда как встроенные и перегруженные * s были сопоставлены. Что я делаю не так? < /p> Подробнее здесь: [url]https://stackoverflow.com/questions/79445695/how-do-i-match-builtin-usages[/url]