llvmbot wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Vlad Serebrennikov (Endilll)

<details>
<summary>Changes</summary>

This issue is concerned with initialization of static objects that are not of 
non-POD class types. It affirms that default initialization of such objects 
that typically leaves them with an indeterminate value does not apply to static 
objects. Instead, such objects undergo zero initialization.

Quoting the period correct wording from N1316 (8.5 Initializers):
&gt; §6
&gt; [core 178: The memory occupied by any → Every ] object of static storage 
duration shall be zero-initialized at program startup before any other 
initialization takes place. [_Note:_ in some cases, additional initialization 
is done later. ]

&gt; §9
&gt; If no initializer is specified for an object, and the object is of 
(possibly cv-qualified) non-POD class type (or array thereof), the object shall 
be default-initialized; if the object is of const-qualified type, the 
underlying class type shall have a user-declared default constructor. 
Otherwise, if no initializer is specified for [core 78: an object, → a 
non-static object, ] the object and its subobjects, if any, have an 
indeterminate initial value (90); if the object or any of its subobjects are of 
const-qualified type, the program is ill-formed.
&gt; (90) This does not apply to aggregate objects with automatic storage 
duration initialized with an incomplete brace-enclosed _initializer-list_; see 
8.5.1.

The current wording still supports this Core issue 
(http://eel.is/c++draft/basic.start#static-2.sentence-2):
&gt; If constant initialization is not performed, a variable with static 
storage duration 
([[basic.stc.static]](http://eel.is/c++draft/basic.stc.static)) or thread 
storage duration 
([[basic.stc.thread]](http://eel.is/c++draft/basic.stc.thread)) is 
zero-initialized 
([[dcl.init]](http://eel.is/c++draft/dcl.init))[.](http://eel.is/c++draft/basic.start#static-2.sentence-2)

It's unfortunate that we have to test this twice: once in `-verify` mode, once 
using `FileCheck`, but they are not compatible. This will be rectified once we 
implement CWG78.

---
Full diff: https://github.com/llvm/llvm-project/pull/93708.diff


3 Files Affected:

- (modified) clang/test/CXX/drs/cwg0xx.cpp (+1-7) 
- (added) clang/test/CXX/drs/cwg78.cpp (+34) 
- (modified) clang/www/cxx_dr_status.html (+1-1) 


``````````diff
diff --git a/clang/test/CXX/drs/cwg0xx.cpp b/clang/test/CXX/drs/cwg0xx.cpp
index 6c600bbc7c3f6..abfaca7fe06e7 100644
--- a/clang/test/CXX/drs/cwg0xx.cpp
+++ b/clang/test/CXX/drs/cwg0xx.cpp
@@ -1180,13 +1180,7 @@ namespace cwg77 { // cwg77: yes
   };
 }
 
-namespace cwg78 { // cwg78: sup ????
-  // Under CWG78, this is valid, because 'k' has static storage duration, so is
-  // zero-initialized.
-  const int k;
-  // expected-error@-1 {{default initialization of an object of const type 
'const int'}}
-}
-
+// cwg78 is in cwg78.cpp
 // cwg79: na
 
 namespace cwg80 { // cwg80: 2.9
diff --git a/clang/test/CXX/drs/cwg78.cpp b/clang/test/CXX/drs/cwg78.cpp
new file mode 100644
index 0000000000000..e0c3b72c537cf
--- /dev/null
+++ b/clang/test/CXX/drs/cwg78.cpp
@@ -0,0 +1,34 @@
+// RUN: %clang_cc1 -std=c++98 %s -verify -DVERIFY -fexceptions 
-fcxx-exceptions -pedantic-errors -triple %itanium_abi_triple
+// RUN: %clang_cc1 -std=c++11 %s -verify -DVERIFY -fexceptions 
-fcxx-exceptions -pedantic-errors -triple %itanium_abi_triple
+// RUN: %clang_cc1 -std=c++14 %s -verify -DVERIFY -fexceptions 
-fcxx-exceptions -pedantic-errors -triple %itanium_abi_triple
+// RUN: %clang_cc1 -std=c++17 %s -verify -DVERIFY -fexceptions 
-fcxx-exceptions -pedantic-errors -triple %itanium_abi_triple
+// RUN: %clang_cc1 -std=c++20 %s -verify -DVERIFY -fexceptions 
-fcxx-exceptions -pedantic-errors -triple %itanium_abi_triple
+// RUN: %clang_cc1 -std=c++23 %s -verify -DVERIFY -fexceptions 
-fcxx-exceptions -pedantic-errors -triple %itanium_abi_triple
+// RUN: %clang_cc1 -std=c++23 %s -verify -DVERIFY -fexceptions 
-fcxx-exceptions -pedantic-errors -triple %itanium_abi_triple
+
+// RUN: %clang_cc1 -std=c++98 %s -triple %itanium_abi_triple -emit-llvm 
-disable-llvm-passes -o - -fexceptions -fcxx-exceptions -pedantic-errors | 
llvm-cxxfilt -n | FileCheck %s --check-prefixes CHECK
+// RUN: %clang_cc1 -std=c++11 %s -triple %itanium_abi_triple -emit-llvm 
-disable-llvm-passes -o - -fexceptions -fcxx-exceptions -pedantic-errors | 
llvm-cxxfilt -n | FileCheck %s --check-prefixes CHECK
+// RUN: %clang_cc1 -std=c++14 %s -triple %itanium_abi_triple -emit-llvm 
-disable-llvm-passes -o - -fexceptions -fcxx-exceptions -pedantic-errors | 
llvm-cxxfilt -n | FileCheck %s --check-prefixes CHECK
+// RUN: %clang_cc1 -std=c++17 %s -triple %itanium_abi_triple -emit-llvm 
-disable-llvm-passes -o - -fexceptions -fcxx-exceptions -pedantic-errors | 
llvm-cxxfilt -n | FileCheck %s --check-prefixes CHECK
+// RUN: %clang_cc1 -std=c++20 %s -triple %itanium_abi_triple -emit-llvm 
-disable-llvm-passes -o - -fexceptions -fcxx-exceptions -pedantic-errors | 
llvm-cxxfilt -n | FileCheck %s --check-prefixes CHECK
+// RUN: %clang_cc1 -std=c++23 %s -triple %itanium_abi_triple -emit-llvm 
-disable-llvm-passes -o - -fexceptions -fcxx-exceptions -pedantic-errors | 
llvm-cxxfilt -n | FileCheck %s --check-prefixes CHECK
+// RUN: %clang_cc1 -std=c++2c %s -triple %itanium_abi_triple -emit-llvm 
-disable-llvm-passes -o - -fexceptions -fcxx-exceptions -pedantic-errors | 
llvm-cxxfilt -n | FileCheck %s --check-prefixes CHECK
+
+namespace cwg78 { // cwg78: partial
+// Under CWG78, this is valid, because 'k' has static storage duration, so is
+// zero-initialized.
+#ifdef VERIFY
+const int k;
+// expected-error@-1 {{default initialization of an object of const type 
'const int'}}
+#endif
+
+int f() {
+  static int i;
+  return i;
+}
+
+// Checking that static variable is zero-initialized,
+// and not default-initialized (which means no initialization in this case).
+
+// CHECK: @cwg78::f()::i = {{.*}} i32 0
+} // namespace cwg78
diff --git a/clang/www/cxx_dr_status.html b/clang/www/cxx_dr_status.html
index 4cce88fe0490f..ff50a11c3f525 100755
--- a/clang/www/cxx_dr_status.html
+++ b/clang/www/cxx_dr_status.html
@@ -506,7 +506,7 @@ <h2 id="cxxdr">C++ defect report implementation status</h2>
     <td><a href="https://cplusplus.github.io/CWG/issues/78.html";>78</a></td>
     <td>CD1</td>
     <td>Section 8.5 paragraph 9 should state it only applies to non-static 
objects</td>
-    <td class="none" align="center">Superseded by <a href="#????">????</a></td>
+    <td class="partial" align="center">Partial</td>
   </tr>
   <tr id="79">
     <td><a href="https://cplusplus.github.io/CWG/issues/79.html";>79</a></td>

``````````

</details>


https://github.com/llvm/llvm-project/pull/93708
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to