public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug middle-end/88175] GCC should not warn within implicit copy-constructor (or should report the implicit function in a special way)
       [not found] <bug-88175-4@http.gcc.gnu.org/bugzilla/>
@ 2021-04-16 20:11 ` msebor at gcc dot gnu.org
  2021-04-17 15:06 ` jg at jguk dot org
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 4+ messages in thread
From: msebor at gcc dot gnu.org @ 2021-04-16 20:11 UTC (permalink / raw)
  To: gcc-bugs

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

Martin Sebor <msebor at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |msebor at gcc dot gnu.org

--- Comment #17 from Martin Sebor <msebor at gcc dot gnu.org> ---
For the test case in attachment 45096 GCC 11 emits a nicer message:

In file included from header.cpp:5:
In member function ‘info& info::operator=(const info&)’,
    inlined from ‘void test(info_t)’ at header.cpp:10:12:
header.h:8:16: warning: ‘copy.info::registered’ is used uninitialized
[-Wuninitialized]
header.cpp: In function ‘void test(info_t)’:
header.cpp:9:12: note: ‘copy’ declared here
In file included from header.cpp:5:
In copy constructor ‘info::info(const info&)’,
    inlined from ‘int main()’ at header.cpp:21:9:
header.h:8:16: warning: ‘temp.info::registered’ is used uninitialized
[-Wuninitialized]
header.cpp: In function ‘int main()’:
header.cpp:19:12: note: ‘temp’ declared here

This looks pretty close to optimal to me.  The caret location for the
implicitly generated copy assignment is not ideal though.  It points to the
class definition like so:

In member function ‘info& info::operator=(const info&)’,
    inlined from ‘void test(info_t)’ at pr88175-c0.C.C:12044:12:
pr88175-c0.C.C:12036:16: warning: ‘copy.info::registered’ is used uninitialized
[-Wuninitialized]
12036 | typedef struct info
      |                ^~~~
pr88175-c0.C.C: In function ‘void test(info_t)’:
pr88175-c0.C.C:12043:12: note: ‘copy’ declared here
12043 |     info_t copy;
      |            ^~~~
In copy constructor ‘info::info(const info&)’,
    inlined from ‘int main()’ at pr88175-c0.C.C:12051:9:
pr88175-c0.C.C:12036:16: warning: ‘temp.info::registered’ is used uninitialized
[-Wuninitialized]
12036 | typedef struct info
      |                ^~~~
pr88175-c0.C.C: In function ‘int main()’:
pr88175-c0.C.C:12050:12: note: ‘temp’ declared here
12050 |     info_t temp;
      |            ^~~~

Pointing to the invocation of the special function might be a better choice. 
That should be doable by testing the DECL_ARTIFICIAL bit and using the other
location instead.

The test case in comment #16 isn't diagnosed by GCC 11 at any optimization
level anymore (a regression caused by r158271).  I think that's something to
handle separately.

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

* [Bug middle-end/88175] GCC should not warn within implicit copy-constructor (or should report the implicit function in a special way)
       [not found] <bug-88175-4@http.gcc.gnu.org/bugzilla/>
  2021-04-16 20:11 ` [Bug middle-end/88175] GCC should not warn within implicit copy-constructor (or should report the implicit function in a special way) msebor at gcc dot gnu.org
@ 2021-04-17 15:06 ` jg at jguk dot org
  2021-04-17 21:30 ` redi at gcc dot gnu.org
  2021-04-18 14:47 ` jg at jguk dot org
  3 siblings, 0 replies; 4+ messages in thread
From: jg at jguk dot org @ 2021-04-17 15:06 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #18 from Jonny Grant <jg at jguk dot org> ---
Hello Martin
It looks better.
May I ask, if the "implicitly generated copy assignment" and "copy constructor"
could be mentioned in the warning that they were implicitly generated?
Thank you, Jonny

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

* [Bug middle-end/88175] GCC should not warn within implicit copy-constructor (or should report the implicit function in a special way)
       [not found] <bug-88175-4@http.gcc.gnu.org/bugzilla/>
  2021-04-16 20:11 ` [Bug middle-end/88175] GCC should not warn within implicit copy-constructor (or should report the implicit function in a special way) msebor at gcc dot gnu.org
  2021-04-17 15:06 ` jg at jguk dot org
@ 2021-04-17 21:30 ` redi at gcc dot gnu.org
  2021-04-18 14:47 ` jg at jguk dot org
  3 siblings, 0 replies; 4+ messages in thread
From: redi at gcc dot gnu.org @ 2021-04-17 21:30 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #19 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Why is that needed? It says the location is something like:

In member function ‘info& info::operator=(const info&)’,

or:

In copy constructor ‘info::info(const info&)’,

If that isn't explicitly defined in the class, then obviously it's being
defined implicitly by the compiler. That property of C++ should not surprise
anybody.

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

* [Bug middle-end/88175] GCC should not warn within implicit copy-constructor (or should report the implicit function in a special way)
       [not found] <bug-88175-4@http.gcc.gnu.org/bugzilla/>
                   ` (2 preceding siblings ...)
  2021-04-17 21:30 ` redi at gcc dot gnu.org
@ 2021-04-18 14:47 ` jg at jguk dot org
  3 siblings, 0 replies; 4+ messages in thread
From: jg at jguk dot org @ 2021-04-18 14:47 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #20 from Jonny Grant <jg at jguk dot org> ---
(In reply to Jonathan Wakely from comment #19)
> Why is that needed? It says the location is something like:
> 
> In member function ‘info& info::operator=(const info&)’,
> 
> or:
> 
> In copy constructor ‘info::info(const info&)’,
> 
> If that isn't explicitly defined in the class, then obviously it's being
> defined implicitly by the compiler. That property of C++ should not surprise
> anybody.

You're point is valid. Highlighting it is implicitly generated is purely an
informative diagnostic.

I've been on C++ teams where certain software engineers weren't aware of
implicitly generated constructors.

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

end of thread, other threads:[~2021-04-18 14:47 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <bug-88175-4@http.gcc.gnu.org/bugzilla/>
2021-04-16 20:11 ` [Bug middle-end/88175] GCC should not warn within implicit copy-constructor (or should report the implicit function in a special way) msebor at gcc dot gnu.org
2021-04-17 15:06 ` jg at jguk dot org
2021-04-17 21:30 ` redi at gcc dot gnu.org
2021-04-18 14:47 ` jg at jguk dot 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).