On 3 April 2018 at 17:19, Ville Voutilainen <ville.voutilai...@gmail.com> wrote: > * parser.c (cp_parser_unqualified_id): Add a new parameter > and check it for the literal diagnostic.
As discussed on irc, we can indeed do better. With this approach, we look at function declarations only, so using-declarations are automatically ok, and we allow friend declarations (that are not definitions) and local declarations. Tested locally/partially on Linux-x64, will test with the full suite if this is ok. On that front.. ..where can this land? This isn't a regression, but it's certainly a long-standing annoyance, but mostly only for -Werror users. I can argue it both ways. 2018-04-04 Ville Voutilainen <ville.voutilai...@gmail.com> gcc/cp PR c++/65923 * decl.c (grokfndecl): Handle standard UDL diagnostics here.. * parser.c (cp_parser_unqualified_id): ..not here. testsuite/ PR c++/65923 * g++.dg/diagnostic/pr65923.C: New.
diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index ba45673..7ea90b4 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -8941,6 +8941,12 @@ grokfndecl (tree ctype, warning (0, "floating point suffix %qs" " shadowed by implementation", suffix); } + /* 17.6.3.3.5 */ + if (suffix[0] != '_' && !in_system_header_at (input_location) + && !current_function_decl && !(friendp && !funcdef_flag)) + warning (OPT_Wliteral_suffix, + "literal operator suffixes not preceded by %<_%>" + " are reserved for future standardization"); } else { diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index d526a4e..f6fbcf6 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -6100,16 +6100,6 @@ cp_parser_unqualified_id (cp_parser* parser, /* If that didn't work, try a conversion-function-id. */ if (!cp_parser_parse_definitely (parser)) id = cp_parser_conversion_function_id (parser); - else if (UDLIT_OPER_P (id)) - { - /* 17.6.3.3.5 */ - const char *name = UDLIT_OP_SUFFIX (id); - if (name[0] != '_' && !in_system_header_at (input_location) - && declarator_p) - warning (OPT_Wliteral_suffix, - "literal operator suffixes not preceded by %<_%>" - " are reserved for future standardization"); - } return id; } diff --git a/gcc/testsuite/g++.dg/diagnostic/pr65923.C b/gcc/testsuite/g++.dg/diagnostic/pr65923.C new file mode 100644 index 0000000..036f447 --- /dev/null +++ b/gcc/testsuite/g++.dg/diagnostic/pr65923.C @@ -0,0 +1,23 @@ +// { dg-do compile { target c++14 } } + +#include <chrono> + +using std::literals::chrono_literals::operator""s; + +struct X +{ + friend constexpr std::chrono::duration<long double> std::literals::chrono_literals::operator""s(long double); +}; + +struct X2 +{ + friend constexpr X operator""foo(long double) {return {};} // { dg-warning "literal operator suffixes not preceded" } +}; + +namespace std +{ + template<> void swap(X&, X&) + { + constexpr std::chrono::duration<long double> operator""s(long double); + } +}