public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/114248] New: invalid "scalar object" error
@ 2024-03-06  2:05 f.heckenbach@fh-soft.de
  2024-03-06  2:11 ` [Bug c++/114248] " pinskia at gcc dot gnu.org
  2024-03-06  2:13 ` pinskia at gcc dot gnu.org
  0 siblings, 2 replies; 3+ messages in thread
From: f.heckenbach@fh-soft.de @ 2024-03-06  2:05 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 114248
           Summary: invalid "scalar object" error
           Product: gcc
           Version: 12.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: f.heckenbach@fh-soft.de
  Target Milestone: ---

% cat test.cpp  
// #pragma GCC diagnostic ignored "-Wnarrowing"
// #pragma GCC diagnostic warning "-Wnarrowing"

template <unsigned> struct S
{
  S (int, int) { }
};

// template <> using S <-1> = int;

int main ()
{
  S <-1> i { 1, 2 };
}
% g++ test.cpp 
test.cpp: In function 'int main()':
test.cpp:13:8: error: narrowing conversion of '-1' from 'int' to 'unsigned int'
[-Wnarrowing]
   13 |   S <-1> i { 1, 2 };
      |        ^
test.cpp:13:10: error: scalar object 'i' requires one element in initializer
   13 |   S <-1> i { 1, 2 };
      |          ^

The first error is correct, of course, but the second one is not because "i" is
not scalar.

Sure, the declaration of "i" is wrong, but this leaves two possible
conclusions:

- We don't know what "i" is meant to be, so any claim about it is unjustified.

- We see that the type of "i" is meant to be an instance of S which is a
struct, and not scalar. AFAIK, even potential specializations of S cannot
change this fact (cf. the commented-out line which is doubly wrong).

Interestingly, when turning the first error off or into a warning (cf. one of
the commented-out pragmas), the second error disappears as well.

I would have expected that those options/pragmas merely control if the
narrowing problem is reported, and if so, whether it causes the compilation to
fail, but apparently it does influence gcc's representation of "i" afterwards
as well.

But that's just a side note actually -- even with a clearly wrong declaration
of "i" such as

  S <""> i { 1, 2 };

gcc gives the "scalar" error which it shouldn't.

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

* [Bug c++/114248] invalid "scalar object" error
  2024-03-06  2:05 [Bug c++/114248] New: invalid "scalar object" error f.heckenbach@fh-soft.de
@ 2024-03-06  2:11 ` pinskia at gcc dot gnu.org
  2024-03-06  2:13 ` pinskia at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-03-06  2:11 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

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

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
There are a few other diagnostic bugs like this one. Basically the front end is
setting the type of the bad decl to int after an error instead of treating as a
bad object.

Iirc this is done before the gcc/front end had a notion of an error mark node.

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

* [Bug c++/114248] invalid "scalar object" error
  2024-03-06  2:05 [Bug c++/114248] New: invalid "scalar object" error f.heckenbach@fh-soft.de
  2024-03-06  2:11 ` [Bug c++/114248] " pinskia at gcc dot gnu.org
@ 2024-03-06  2:13 ` pinskia at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-03-06  2:13 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |DUPLICATE
             Status|UNCONFIRMED                 |RESOLVED

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Dup

*** This bug has been marked as a duplicate of bug 104113 ***

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

end of thread, other threads:[~2024-03-06  2:13 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-06  2:05 [Bug c++/114248] New: invalid "scalar object" error f.heckenbach@fh-soft.de
2024-03-06  2:11 ` [Bug c++/114248] " pinskia at gcc dot gnu.org
2024-03-06  2:13 ` 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).