aboutsummaryrefslogtreecommitdiff
path: root/gcc/doc
diff options
context:
space:
mode:
authorMarek Polacek <polacek@redhat.com>2020-09-19 16:17:42 -0400
committerMarek Polacek <polacek@redhat.com>2020-09-21 17:48:11 -0400
commit7029dfa38b663d20e0de40395fcd45a2845e2f71 (patch)
tree8e17199e922c860dc4b9227e1a01b94d56e4a8c9 /gcc/doc
parent68402af1c68301c6bc852ddba6c63966ed706178 (diff)
downloadgcc-7029dfa38b663d20e0de40395fcd45a2845e2f71.zip
gcc-7029dfa38b663d20e0de40395fcd45a2845e2f71.tar.gz
gcc-7029dfa38b663d20e0de40395fcd45a2845e2f71.tar.bz2
c++: Implement -Wctad-maybe-unsupported.
I noticed that clang++ has this CTAD warning and thought that it might be useful to have it. From clang++: "Some style guides want to allow using CTAD only on types that "opt-in"; i.e. on types that are designed to support it and not just types that *happen* to work with it." So this warning warns when CTAD deduced a type, but the type does not define any deduction guides. In that case CTAD worked only because the compiler synthesized the implicit deduction guides. That might not be intended. It can be suppressed by adding a deduction guide that will never be considered: struct allow_ctad_t; template <typename T> struct S { S(T) {} }; S(allow_ctad_t) -> S<void>; This warning is off by default. It doesn't warn when the type comes from a system header unless -Wsystem-headers. gcc/c-family/ChangeLog: * c.opt (Wctad-maybe-unsupported): New option. gcc/cp/ChangeLog: * pt.c (deduction_guides_for): Add a bool parameter. Set it. (do_class_deduction): Warn when CTAD succeeds but the type doesn't have any explicit deduction guides. gcc/ChangeLog: * doc/invoke.texi: Document -Wctad-maybe-unsupported. gcc/testsuite/ChangeLog: * g++.dg/warn/Wctad-maybe-unsupported.C: New test. * g++.dg/warn/Wctad-maybe-unsupported2.C: New test. * g++.dg/warn/Wctad-maybe-unsupported3.C: New test. * g++.dg/warn/Wctad-maybe-unsupported.h: New file.
Diffstat (limited to 'gcc/doc')
-rw-r--r--gcc/doc/invoke.texi22
1 files changed, 21 insertions, 1 deletions
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index 8be2b4f..665c0ff 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -236,7 +236,8 @@ in the following sections.
-Wabi-tag -Wcatch-value -Wcatch-value=@var{n} @gol
-Wno-class-conversion -Wclass-memaccess @gol
-Wcomma-subscript -Wconditionally-supported @gol
--Wno-conversion-null -Wctor-dtor-privacy -Wno-delete-incomplete @gol
+-Wno-conversion-null -Wctad-maybe-unsupported @gol
+-Wctor-dtor-privacy -Wno-delete-incomplete @gol
-Wdelete-non-virtual-dtor -Wdeprecated-copy -Wdeprecated-copy-dtor @gol
-Weffc++ -Wextra-semi -Wno-inaccessible-base @gol
-Wno-inherited-variadic-ctor -Wno-init-list-lifetime @gol
@@ -3304,6 +3305,25 @@ void f(int *a, int b, int c) @{
Enabled by default with @option{-std=c++20}.
+@item -Wctad-maybe-unsupported @r{(C++ and Objective-C++ only)}
+@opindex Wctad-maybe-unsupported
+@opindex Wno-ctad-maybe-unsupported
+Warn when performing class template argument deduction (CTAD) on a type with
+no explicitly written deduction guides. This warning will point out cases
+where CTAD succeeded only because the compiler synthesized the implicit
+deduction guides, which might not be what the programmer intended. Certain
+style guides allow CTAD only on types that specifically "opt-in"; i.e., on
+types that are designed to support CTAD. This warning can be suppressed with
+the following pattern:
+
+@smallexample
+struct allow_ctad_t; // any name works
+template <typename T> struct S @{
+ S(T) @{ @}
+@};
+S(allow_ctad_t) -> S<void>; // guide with incomplete parameter type will never be considered
+@end smallexample
+
@item -Wctor-dtor-privacy @r{(C++ and Objective-C++ only)}
@opindex Wctor-dtor-privacy
@opindex Wno-ctor-dtor-privacy