Last July we agreed to remove the convention that declarations of
POD classes use the class-key struct (and others class). Attached
is a patch to update the GCC Coding Conventions and the rationale
to reflect the decision. I replaced it with a mild suggestion to
use struct for C structs and class for all others, that I Jason
and Jonathan preferred but tried to make it clear it wasn't a hard
and fast rule.
Martin
PR 61339 - mismatch between struct and class [-Wmismatched-tags]
ChangeLog:
* htdocs/codingconventions.html (Struct Definitions): Remove
old convention.
(Class Definitions): Same.
* htdocs/codingrationale.html (Struct Definitions): Document
convention change.
diff --git a/htdocs/codingconventions.html b/htdocs/codingconventions.html
index 03a77063..f4732ef6 100644
--- a/htdocs/codingconventions.html
+++ b/htdocs/codingconventions.html
@@ -888,9 +888,20 @@ Variables may be simultaneously defined and tested in control expressions.
Struct Definitions
-Use the struct keyword for
-https://en.wikipedia.org/wiki/Plain_old_data_structure;>
-plain old data (POD) types.
+Some coding conventions, including GCC's own in the past, recommend
+using the struct keyword (also known as the class-key)
+for https://en.wikipedia.org/wiki/Plain_old_data_structure;>
+plain old data (POD) types. However, since the POD concept has been
+replaced in C++ by a set of much more nuanced distinctions, the current
+guidance (though not a requirement) is to use the struct
+class-key when defining structures that could be used without
+change in C, and use class for all other classes. It is
+recommended to use the same class-key consistently in all
+declarations and, if necessary, in uses of the class.
+The -Wmismatched-tags warning option helps detect mismatches.
+The -Wredundant-tags GCC option further helps identify places
+where the class-key can safely be omitted.
+
@@ -900,14 +911,13 @@ plain old data (POD) types.
Class Definitions
-Use the class keyword for
-https://en.wikipedia.org/wiki/Plain_old_data_structure;>
-non-POD types.
+See the guidance in Struct Definitions for
+the suggested choice of a class-key.
-A non-POD type will often (but not always)
-have a declaration of a
+A class defined with the class-key class type will often
+(but not always) ave a declaration of a
https://en.wikipedia.org/wiki/Special_member_functions;>
special member function.
If any one of these is declared,
diff --git a/htdocs/codingrationale.html b/htdocs/codingrationale.html
index a2618b64..0b44f1da 100644
--- a/htdocs/codingrationale.html
+++ b/htdocs/codingrationale.html
@@ -54,15 +54,16 @@ if (info *q = get_any_available_info ()) {
Struct Definitions
-In the C++ standard,
-structs and classes differ only in the default access rules.
-We prefer to use these two keywords to signal more information.
-
-
-
-Note that under this definition,
-structs may have member functions.
-This freedom is useful for transitional code.
+In the C++ standard, structs and classes differ only in the default
+access rules. In the past, there was a mild preference among some
+GCC developers for using these two keywords to indicate whether or
+not a class met the criteria for a Plain Old Data (POD) type.
+However, this convention was never consistently adhered to or fully
+socialized. A review of a patch to
+https://gcc.gnu.org/pipermail/gcc-patches/2019-July/525526.html;>
+add support for POD struct convention (PR 61339) revealed that
+the convention lacked broad enough support within the GCC developer
+community. As a result, the convention was removed.