From: Daniel Arndt Date: Sun, 29 Apr 2018 23:10:45 +0000 (+0200) Subject: Clarify that base/reference causes stack-use-after-scope X-Git-Tag: v9.0.0-rc1~64^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F6392%2Fhead;p=dealii.git Clarify that base/reference causes stack-use-after-scope --- diff --git a/tests/base/reference.cc b/tests/base/reference.cc index 32c1c3971d..ac83b41c51 100644 --- a/tests/base/reference.cc +++ b/tests/base/reference.cc @@ -60,44 +60,37 @@ int main() initlog(); - try - { - Test a("A"); - const Test &b("B"); + Test a("A"); + const Test &b("B"); - SmartPointer r(&a, "Test R"); - SmartPointer s(&a, "const Test S"); + SmartPointer r(&a, "Test R"); + SmartPointer s(&a, "const Test S"); // SmartPointer t=&b; // this one should not work - SmartPointer t(const_cast(&b), "Test T"); - SmartPointer 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 t(const_cast(&b), "Test T"); + SmartPointer 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. }