public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/101213] New: Improve support for decltype(std)
@ 2021-06-25 16:37 llvm at rifkin dot dev
  2021-06-25 16:54 ` [Bug c++/101213] " redi at gcc dot gnu.org
  2021-06-25 17:53 ` llvm at rifkin dot dev
  0 siblings, 2 replies; 3+ messages in thread
From: llvm at rifkin dot dev @ 2021-06-25 16:37 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 101213
           Summary: Improve support for decltype(std)
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: llvm at rifkin dot dev
  Target Milestone: ---

Gcc treats decltype(std) as an integer. It only works in some situations
though:

// OK
decltype(std) a;
static_assert(std::is_same<int, decltype(a)>::value);

// Not OK
static_assert(std::is_same<int, decltype(std)>::value);

// OK
decltype(std) a;
using b = decltype(a);
using c = b;

// Not OK
using a = decltype(std);
using b = a;

decltype(std) foo(int a) {} // OK
auto foo() -> decltype(std) {} // OK
void foo(decltype(std) a) {} // Not OK

// Not OK
std::vector<decltype(std)> v;

This bug is hilarious please improve support for it and make it a feature :)
It's invaluable for code bowling and nerd sniping.

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

* [Bug c++/101213] Improve support for decltype(std)
  2021-06-25 16:37 [Bug c++/101213] New: Improve support for decltype(std) llvm at rifkin dot dev
@ 2021-06-25 16:54 ` redi at gcc dot gnu.org
  2021-06-25 17:53 ` llvm at rifkin dot dev
  1 sibling, 0 replies; 3+ messages in thread
From: redi at gcc dot gnu.org @ 2021-06-25 16:54 UTC (permalink / raw)
  To: gcc-bugs

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

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |diagnostic

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
This is just how GCC recovers from a bad parse, so that it can attempt to
continue and give diagnostics for the rest of the code. An invalid type in
certain declaration contexts is replaced with 'int'. Often it does more harm
than good, because you get errors about int::foo being invalid because it's not
a class type (which is true, but then it wasn't int in the original code!)

I've sometimes wondered whether it would be better to use an invented,
incomplete class type as the default instead of int. On balance, most
un-parseable types are probably classes, not fundamental types.

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

* [Bug c++/101213] Improve support for decltype(std)
  2021-06-25 16:37 [Bug c++/101213] New: Improve support for decltype(std) llvm at rifkin dot dev
  2021-06-25 16:54 ` [Bug c++/101213] " redi at gcc dot gnu.org
@ 2021-06-25 17:53 ` llvm at rifkin dot dev
  1 sibling, 0 replies; 3+ messages in thread
From: llvm at rifkin dot dev @ 2021-06-25 17:53 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Jeremy R. <llvm at rifkin dot dev> ---
(In reply to Jonathan Wakely from comment #1)
> This is just how GCC recovers from a bad parse, so that it can attempt to
> continue and give diagnostics for the rest of the code. An invalid type in
> certain declaration contexts is replaced with 'int'. Often it does more harm
> than good, because you get errors about int::foo being invalid because it's
> not a class type (which is true, but then it wasn't int in the original
> code!)
> 
> I've sometimes wondered whether it would be better to use an invented,
> incomplete class type as the default instead of int. On balance, most
> un-parseable types are probably classes, not fundamental types.

That's super cool, thanks for the insight into why decltype(std) is replaced
with int in the first place. Is the substitution but lack of diagnostic
intentional in a case like this https://godbolt.org/z/K91j35rTs? The lack of
diagnostic is of course appreciated for code bowling :)

What's the reason why this substitution is only made in certain contexts?

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

end of thread, other threads:[~2021-06-25 17:53 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-25 16:37 [Bug c++/101213] New: Improve support for decltype(std) llvm at rifkin dot dev
2021-06-25 16:54 ` [Bug c++/101213] " redi at gcc dot gnu.org
2021-06-25 17:53 ` llvm at rifkin dot dev

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).