Bug 90243 - diagnostic notes that belong to a suppressed error about an uninitialized variable in a constexpr function are still shown
Summary: diagnostic notes that belong to a suppressed error about an uninitialized var...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 9.0
: P3 normal
Target Milestone: 10.0
Assignee: Jonathan Wakely
URL:
Keywords: diagnostic, patch
: 91070 92519 (view as bug list)
Depends on:
Blocks: constexpr
  Show dependency treegraph
 
Reported: 2019-04-25 08:12 UTC by Matthias Kretz (Vir)
Modified: 2020-01-17 15:32 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail: 7.4.0, 8.3.0, 9.0
Last reconfirmed: 2019-04-25 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Matthias Kretz (Vir) 2019-04-25 08:12:41 UTC
Test case (https://godbolt.org/z/34KB20):

struct Z {
  int y;
};

template <class T>
constexpr Z f(const T *data) {
  Z z;
  __builtin_memcpy(&z, data, sizeof(z));
  return z;
}

constexpr Z g(const char *data) { return f(data); }

This prints:
<source>: In instantiation of 'constexpr Z f(const T*) [with T = char]':
<source>:12:48:   required from here
<source>:1:8: note: 'struct Z' has no user-provided default constructor
<source>:2:7: note: and the implicitly-defined constructor does not initialize 'int Z::y'

If f is not a template, `Z z;` is an error and the notes explain the error. But when f is a template the error is suppressed (seems correct). However the notes that explain the error are still shown. Whether the notes are shown should use the same condition as the error.
Comment 1 Jonathan Wakely 2019-04-25 19:07:38 UTC
Up to GCC 7.2 there's an error for the example, with notes. The error was fixed by r251429 for PR 80935 (and with r252943 on gcc-7-branch) so from 7.3 the error isn't given, but the notes remain.
Comment 2 Jonathan Wakely 2019-04-25 20:32:10 UTC
Patch posted to https://gcc.gnu.org/ml/gcc-patches/2019-04/msg01009.html
Comment 3 Jonathan Wakely 2019-04-26 16:33:35 UTC
Author: redi
Date: Fri Apr 26 16:33:02 2019
New Revision: 270610

URL: https://gcc.gnu.org/viewcvs?rev=270610&root=gcc&view=rev
Log:
PR c++/90243 - orphaned note in uninstantiated constexpr function

gcc/cp:

	PR c++/90243 - orphaned note in uninstantiated constexpr function
	* decl.c (check_for_uninitialized_const_var): Suppress notes if no
	error was shown.

gcc/testsuite:

	PR c++/90243
	* g++.dg/diagnostic/pr90243.C: New test.

Added:
    trunk/gcc/testsuite/g++.dg/diagnostic/pr90243.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/decl.c
    trunk/gcc/testsuite/ChangeLog
Comment 4 Jonathan Wakely 2019-04-26 16:33:57 UTC
Fixed on trunk.
Comment 5 Jonathan Wakely 2019-07-03 12:51:35 UTC
*** Bug 91070 has been marked as a duplicate of this bug. ***
Comment 6 Jonathan Wakely 2019-11-15 13:53:55 UTC
This is still present on gcc-8-branch and gcc-9-branch.
Comment 7 Jonathan Wakely 2019-11-15 14:28:18 UTC
*** Bug 92519 has been marked as a duplicate of this bug. ***
Comment 8 Jonathan Wakely 2020-01-17 15:32:51 UTC
*** Bug 93311 has been marked as a duplicate of this bug. ***