[Bug c++/105511] [12/13 Regression] Spurious warning: "expected 'template' keyword..." when lt and gt compare over ternary
mpolacek at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Mon Oct 31 20:43:19 GMT 2022
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105511
Marek Polacek <mpolacek at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |mpolacek at gcc dot gnu.org
--- Comment #2 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
I'm not sure if there's anything to fix; the manual says:
In rare cases it is possible to get false positives. To silence this, wrap
the expression in parentheses. For example, the following is treated as a
template, even where m and N are integers:
@smallexample
void NotATemplate (my_class t)
@{
int N = 5;
bool test = t.m < N > (0); // Treated as a template.
test = (t.m < N) > (0); // Same meaning, but not treated as a template.
@}
@end smallexample
so
return ascending ? (a.value < (*b).value) : a.value > (*b).value;
prevents the warning.
More information about the Gcc-bugs
mailing list