public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/68288] botched floating-point UDL
       [not found] <bug-68288-4@http.gcc.gnu.org/bugzilla/>
@ 2020-10-11 21:59 ` solodon at mail dot com
  2020-10-11 22:16 ` solodon at mail dot com
  2021-08-07 20:17 ` pinskia at gcc dot gnu.org
  2 siblings, 0 replies; 3+ messages in thread
From: solodon at mail dot com @ 2020-10-11 21:59 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68288

Yuriy Solodkyy <solodon at mail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |solodon at mail dot com

--- Comment #3 from Yuriy Solodkyy <solodon at mail dot com> ---
This seems to be a genuine bug in GCC, not specific to floating-point UDL. It
is still present in GCC 10.2. ICC barks on it as well, but Clang and MSVC
accepts. 

Consider:

struct s_points { unsigned long long value; };
inline s_points operator"" _sp(unsigned long long v) { return {v}; }

s_points operator+(s_points, s_points);
s_points operator-(s_points, s_points);

s_points foo(s_points p)
{
    return p-42_sp+1_sp; // Put space before + here and GCC will accept the
code
}

I get the following error on return statement line above:

<source>:9:14: error: unable to find numeric literal operator
'operator""_sp+1_sp'

    9 |     return p-42_sp+1_sp;
      |              ^~~~~~~~~~

Since ud-suffix is just an identifier in the grammar, it should not grab +
while parsing, which according to error is what it seems to be doing.

Here is this snippet on Compiler Explorer: https://godbolt.org/z/4bfs6P

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug c++/68288] botched floating-point UDL
       [not found] <bug-68288-4@http.gcc.gnu.org/bugzilla/>
  2020-10-11 21:59 ` [Bug c++/68288] botched floating-point UDL solodon at mail dot com
@ 2020-10-11 22:16 ` solodon at mail dot com
  2021-08-07 20:17 ` pinskia at gcc dot gnu.org
  2 siblings, 0 replies; 3+ messages in thread
From: solodon at mail dot com @ 2020-10-11 22:16 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68288

--- Comment #4 from Yuriy Solodkyy <solodon at mail dot com> ---
P.S. I added my previous example to this bug as they seemed to be related, feel
free to split it into a separate bug if they are not.

P.P.S. Change that return expression to 42_sp-p and the parser seems to think
the entire _sp-p is a UDL suffix:

<source>:9:12: error: unable to find numeric literal operator 'operator""_sp-p'

    9 |     return 42_sp-p;
      |            ^~~~~~~

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug c++/68288] botched floating-point UDL
       [not found] <bug-68288-4@http.gcc.gnu.org/bugzilla/>
  2020-10-11 21:59 ` [Bug c++/68288] botched floating-point UDL solodon at mail dot com
  2020-10-11 22:16 ` solodon at mail dot com
@ 2021-08-07 20:17 ` pinskia at gcc dot gnu.org
  2 siblings, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-08-07 20:17 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68288

--- Comment #5 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
GCC, ICC, and clang all reject this.
MSVC accepts this.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-08-07 20:17 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <bug-68288-4@http.gcc.gnu.org/bugzilla/>
2020-10-11 21:59 ` [Bug c++/68288] botched floating-point UDL solodon at mail dot com
2020-10-11 22:16 ` solodon at mail dot com
2021-08-07 20:17 ` pinskia at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).