diff mbox

[C++] DR 1453

Message ID 54058FE1.3090805@oracle.com
State New
Headers show

Commit Message

Paolo Carlini Sept. 2, 2014, 9:37 a.m. UTC
Hi,

while looking into c++/58102 and DR 1405 I noticed that we don't 
implement DR 1453 either, sort of dual issue with volatile instead of 
mutable. Tested x86_64-linux.

Thanks,
Paolo.

////////////////////////
/cp
2014-09-02  Paolo Carlini  <paolo.carlini@oracle.com>

	DR 1453
	* class.c (check_field_decls): A class of literal type cannot have
	volatile non-static data members and base classes.
	(explain_non_literal_class): Update.

/testsuite
2014-09-02  Paolo Carlini  <paolo.carlini@oracle.com>

	DR 1453
	* g++.dg/cpp0x/constexpr-volatile.C: New.
	* g++.dg/ext/is_literal_type2.C: Likewise.

Comments

Jason Merrill Sept. 2, 2014, 2:13 p.m. UTC | #1
OK.

Jason
diff mbox

Patch

Index: cp/class.c
===================================================================
--- cp/class.c	(revision 214808)
+++ cp/class.c	(working copy)
@@ -3528,9 +3528,11 @@  check_field_decls (tree t, tree *access_decls,
 	CLASSTYPE_NON_AGGREGATE (t) = 1;
 
       /* If at least one non-static data member is non-literal, the whole
-         class becomes non-literal.  Note: if the type is incomplete we
-	 will complain later on.  */
-      if (COMPLETE_TYPE_P (type) && !literal_type_p (type))
+         class becomes non-literal.  Per Core/1453, volatile non-static
+	 data members and base classes are also not allowed.
+	 Note: if the type is incomplete we will complain later on.  */
+      if (COMPLETE_TYPE_P (type)
+	  && (!literal_type_p (type) || CP_TYPE_VOLATILE_P (type))) 
         CLASSTYPE_LITERAL_P (t) = false;
 
       /* A standard-layout class is a class that:
@@ -5431,6 +5433,9 @@  explain_non_literal_class (tree t)
 	      if (CLASS_TYPE_P (ftype))
 		explain_non_literal_class (ftype);
 	    }
+	  if (CP_TYPE_VOLATILE_P (ftype))
+	    inform (0, "  non-static data member %q+D has "
+		    "volatile type", field);
 	}
     }
 }
Index: testsuite/g++.dg/cpp0x/constexpr-volatile.C
===================================================================
--- testsuite/g++.dg/cpp0x/constexpr-volatile.C	(revision 0)
+++ testsuite/g++.dg/cpp0x/constexpr-volatile.C	(working copy)
@@ -0,0 +1,26 @@ 
+// DR 1453
+// { dg-do compile { target c++11 } }
+
+struct S {
+  constexpr S() : n{} { }
+  volatile int n;
+};
+
+constexpr S s;  // { dg-error "literal" }
+
+struct Z {
+  volatile int m;
+};
+
+struct T {
+  constexpr T() : n{} { }
+  Z n;
+};
+
+constexpr T t;  // { dg-error "literal" }
+
+struct U : Z {
+  constexpr U() : Z{} { }
+};
+
+constexpr U u;  // { dg-error "literal" }
Index: testsuite/g++.dg/ext/is_literal_type2.C
===================================================================
--- testsuite/g++.dg/ext/is_literal_type2.C	(revision 0)
+++ testsuite/g++.dg/ext/is_literal_type2.C	(working copy)
@@ -0,0 +1,26 @@ 
+// DR 1453
+// { dg-do compile { target c++11 } }
+
+struct S {
+  constexpr S() : n{} { }
+  volatile int n;
+};
+
+static_assert(!__is_literal_type(S), "");
+
+struct Z {
+  volatile int m;
+};
+
+struct T {
+  constexpr T() : n{} { }
+  Z n;
+};
+
+static_assert(!__is_literal_type(T), "");
+
+struct U : Z {
+  constexpr U() : Z{} { }
+};
+
+static_assert(!__is_literal_type(U), "");