public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/98620] New: SFINAE code in class specialization generate warnings
@ 2021-01-11 13:42 m.cencora at gmail dot com
2021-01-11 15:01 ` [Bug c++/98620] SFINAE code in class specialization generates warnings redi at gcc dot gnu.org
` (4 more replies)
0 siblings, 5 replies; 6+ messages in thread
From: m.cencora at gmail dot com @ 2021-01-11 13:42 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98620
Bug ID: 98620
Summary: SFINAE code in class specialization generate warnings
Product: gcc
Version: 11.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: m.cencora at gmail dot com
Target Milestone: ---
Following code compiled in any gcc>=5, C++11 or higher, and
-Wmissing-field-initializers generate compiler warning:
g++ -std=c++20 -Wmissing-field-initializers
#include <type_traits>
template <typename T>
struct TmpArray
{
T arr[1];
};
template <typename Src, typename Dst, typename = void>
struct is_non_narrowing_conversion : std::false_type
{};
template <typename Src, typename Dst>
struct is_non_narrowing_conversion<
Src, Dst,
decltype(void(TmpArray<Dst>{{ std::declval<Src>() }}))
> : std::true_type
{};
struct mystruct
{
int a;
void * b;
};
void test_nok()
{
is_non_narrowing_conversion<int&, mystruct>::type v;
}
SFINAE is used here only to detect if a code compiles, and code inside the
decltype should not generate warnings.
Also this is inconsistent, because when SFINAE is used in function template the
warning is not generated:
template <typename Dst, typename Src>
auto is_non_narrowing_conversion_func_impl(Src&&, int)
-> decltype((TmpArray<Dst>{{ std::declval<Src>() }}, std::true_type{}));
template <typename Dst, typename Src>
auto is_non_narrowing_conversion_func_impl(Src&&, ...)
-> std::false_type;
template <typename Src, typename Dst>
using is_non_narrowing_conversion_v2 =
decltype(is_non_narrowing_conversion_func_impl<Dst>(std::declval<Src>(), 0));
void test_ok()
{
is_non_narrowing_conversion_v2<int&, mystruct> v;
}
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/98620] SFINAE code in class specialization generates warnings
2021-01-11 13:42 [Bug c++/98620] New: SFINAE code in class specialization generate warnings m.cencora at gmail dot com
@ 2021-01-11 15:01 ` redi at gcc dot gnu.org
2021-01-11 15:24 ` mpolacek at gcc dot gnu.org
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: redi at gcc dot gnu.org @ 2021-01-11 15:01 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98620
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Last reconfirmed| |2021-01-11
Status|UNCONFIRMED |NEW
Ever confirmed|0 |1
Keywords| |diagnostic
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/98620] SFINAE code in class specialization generates warnings
2021-01-11 13:42 [Bug c++/98620] New: SFINAE code in class specialization generate warnings m.cencora at gmail dot com
2021-01-11 15:01 ` [Bug c++/98620] SFINAE code in class specialization generates warnings redi at gcc dot gnu.org
@ 2021-01-11 15:24 ` mpolacek at gcc dot gnu.org
2021-01-11 23:19 ` mpolacek at gcc dot gnu.org
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2021-01-11 15:24 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98620
Marek Polacek <mpolacek at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |patch
CC| |mpolacek at gcc dot gnu.org
--- Comment #1 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Can be fixed like this:
--- a/gcc/cp/typeck2.c
+++ b/gcc/cp/typeck2.c
@@ -1563,6 +1563,7 @@ process_init_constructor_record (tree type, tree init,
int nested, int flags,
/* Warn when some struct elements are implicitly initialized. */
if ((complain & tf_warning)
+ && !cp_unevaluated_operand
&& !EMPTY_CONSTRUCTOR_P (init))
warning (OPT_Wmissing_field_initializers,
"missing initializer for member %qD", field);
@@ -1593,6 +1594,7 @@ process_init_constructor_record (tree type, tree init,
int nested, int flags,
/* Warn when some struct elements are implicitly initialized
to zero. */
if ((complain & tf_warning)
+ && !cp_unevaluated_operand
&& !EMPTY_CONSTRUCTOR_P (init))
warning (OPT_Wmissing_field_initializers,
"missing initializer for member %qD", field);
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/98620] SFINAE code in class specialization generates warnings
2021-01-11 13:42 [Bug c++/98620] New: SFINAE code in class specialization generate warnings m.cencora at gmail dot com
2021-01-11 15:01 ` [Bug c++/98620] SFINAE code in class specialization generates warnings redi at gcc dot gnu.org
2021-01-11 15:24 ` mpolacek at gcc dot gnu.org
@ 2021-01-11 23:19 ` mpolacek at gcc dot gnu.org
2021-01-12 3:31 ` cvs-commit at gcc dot gnu.org
2021-01-12 3:32 ` mpolacek at gcc dot gnu.org
4 siblings, 0 replies; 6+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2021-01-11 23:19 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98620
Marek Polacek <mpolacek at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Assignee|unassigned at gcc dot gnu.org |mpolacek at gcc dot gnu.org
Status|NEW |ASSIGNED
--- Comment #2 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Posted to ML.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/98620] SFINAE code in class specialization generates warnings
2021-01-11 13:42 [Bug c++/98620] New: SFINAE code in class specialization generate warnings m.cencora at gmail dot com
` (2 preceding siblings ...)
2021-01-11 23:19 ` mpolacek at gcc dot gnu.org
@ 2021-01-12 3:31 ` cvs-commit at gcc dot gnu.org
2021-01-12 3:32 ` mpolacek at gcc dot gnu.org
4 siblings, 0 replies; 6+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-01-12 3:31 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98620
--- Comment #3 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Marek Polacek <mpolacek@gcc.gnu.org>:
https://gcc.gnu.org/g:814299a9d49c25ae2e8d00ec619559b71833871a
commit r11-6606-g814299a9d49c25ae2e8d00ec619559b71833871a
Author: Marek Polacek <polacek@redhat.com>
Date: Mon Jan 11 11:44:36 2021 -0500
c++: -Wmissing-field-initializers in unevaluated ctx [PR98620]
This PR wants us not to warn about missing field initializers when
the code in question takes places in decltype and similar. Fixed
thus.
gcc/cp/ChangeLog:
PR c++/98620
* typeck2.c (process_init_constructor_record): Don't emit
-Wmissing-field-initializers warnings in unevaluated contexts.
gcc/testsuite/ChangeLog:
PR c++/98620
* g++.dg/warn/Wmissing-field-initializers-2.C: New test.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/98620] SFINAE code in class specialization generates warnings
2021-01-11 13:42 [Bug c++/98620] New: SFINAE code in class specialization generate warnings m.cencora at gmail dot com
` (3 preceding siblings ...)
2021-01-12 3:31 ` cvs-commit at gcc dot gnu.org
@ 2021-01-12 3:32 ` mpolacek at gcc dot gnu.org
4 siblings, 0 replies; 6+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2021-01-12 3:32 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98620
Marek Polacek <mpolacek at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|ASSIGNED |RESOLVED
Resolution|--- |FIXED
--- Comment #4 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Fixed.
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2021-01-12 3:32 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-11 13:42 [Bug c++/98620] New: SFINAE code in class specialization generate warnings m.cencora at gmail dot com
2021-01-11 15:01 ` [Bug c++/98620] SFINAE code in class specialization generates warnings redi at gcc dot gnu.org
2021-01-11 15:24 ` mpolacek at gcc dot gnu.org
2021-01-11 23:19 ` mpolacek at gcc dot gnu.org
2021-01-12 3:31 ` cvs-commit at gcc dot gnu.org
2021-01-12 3:32 ` mpolacek 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).