diff gcc/testsuite/g++.dg/torture/pr93246.C @ 145:1830386684a0

gcc-9.2.0
author anatofuz
date Thu, 13 Feb 2020 11:34:05 +0900
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gcc/testsuite/g++.dg/torture/pr93246.C	Thu Feb 13 11:34:05 2020 +0900
@@ -0,0 +1,31 @@
+// { dg-do run }
+// { dg-additional-options "-fstrict-aliasing" }
+
+template <typename = void> struct Optional {
+  auto is_present() const { const bool &p = inner.present; return p; }
+  auto set_present() { if (not is_present()) inner.present = true; }
+  struct InnerType {
+    bool present = false;
+    char padding[1] = {0};
+  };
+  using inner_t = InnerType;
+  inner_t inner = {};
+};
+
+template <typename WrappedType> struct Wrapper {
+  auto operator-> () { return value; }
+  WrappedType *value;
+};
+
+void __attribute__((noipa)) foo(Optional<>& x) {}
+
+int main()
+{
+  Optional<> buf{};
+  foo(buf);
+  Wrapper<Optional<>> wo = {&buf};
+  wo->set_present();
+  auto x = wo->is_present();
+  if (!x)
+    __builtin_abort ();
+}