]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Clarify that base/reference causes stack-use-after-scope 6392/head
authorDaniel Arndt <daniel.arndt@iwr.uni-heidelberg.de>
Sun, 29 Apr 2018 23:10:45 +0000 (01:10 +0200)
committerDaniel Arndt <daniel.arndt@iwr.uni-heidelberg.de>
Sun, 29 Apr 2018 23:52:04 +0000 (01:52 +0200)
tests/base/reference.cc

index 32c1c3971deaad9160803882c6203a427c6106fb..ac83b41c512af7a6d3c0131b8285f56b88be12b2 100644 (file)
@@ -60,44 +60,37 @@ int main()
 
   initlog();
 
-  try
-    {
-      Test a("A");
-      const Test &b("B");
+  Test a("A");
+  const Test &b("B");
 
-      SmartPointer<Test,Test>       r(&a, "Test R");
-      SmartPointer<const Test,Test> s(&a, "const Test S");
+  SmartPointer<Test,Test>       r(&a, "Test R");
+  SmartPointer<const Test,Test> s(&a, "const Test S");
 //  SmartPointer<Test,Test>       t=&b;    // this one should not work
-      SmartPointer<Test,Test>       t(const_cast<Test *>(&b), "Test T");
-      SmartPointer<const Test,Test> u(&b, "const Test");
-
-
-      deallog << "a ";
-      a.f();            // should print "mutable", since #a# is not const
-      deallog << "b ";
-      b.f();            // should print "const", since #b# is const
-      deallog << "r ";
-      r->f();           // should print "mutable", since it points to the non-const #a#
-      deallog << "s ";
-      s->f();           // should print "const", since it points to the const #b#
-      // but we made it const
-      deallog << "t ";
-      t->f();           // should print "mutable", since #b# is const, but
-      // we casted the constness away
-      deallog << "u ";
-      u->f();           // should print "const" since #b# is const
-      // Now try if subscriptor works
-      Test c("C");
-      r = &c;
-      Test d("D");
-      r = &d;
-      // Destruction of "Test R" will cause a spurious ExcNotUsed here,
-      // since D was deleted first
-    }
-  catch (ExceptionBase &e)
-    {
-      deallog << e.get_exc_name() << std::endl;
-    }
-
+  SmartPointer<Test,Test>       t(const_cast<Test *>(&b), "Test T");
+  SmartPointer<const Test,Test> u(&b, "const Test");
+
+
+  deallog << "a ";
+  a.f();            // should print "mutable", since #a# is not const
+  deallog << "b ";
+  b.f();            // should print "const", since #b# is const
+  deallog << "r ";
+  r->f();           // should print "mutable", since it points to the non-const #a#
+  deallog << "s ";
+  s->f();           // should print "const", since it points to the const #b#
+  // but we made it const
+  deallog << "t ";
+  t->f();           // should print "mutable", since #b# is const, but
+  // we casted the constness away
+  deallog << "u ";
+  u->f();           // should print "const" since #b# is const
+  // Now try if subscriptor works
+  Test c("C");
+  r = &c;
+  Test d("D");
+  r = &d;
+  // Destruction of "Test R" will cause a spurious ExcNotUsed here,
+  // since D was deleted first. This shows up in address sanitizers
+  // as stack-use-after-scope, but we can't do anything about it.
 }
 

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.