[LLVMbugs] [Bug 12677] New: Warn when captured const reference (of temorary) becomes stale

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Thu Apr 26 12:23:47 PDT 2012


http://llvm.org/bugs/show_bug.cgi?id=12677

             Bug #: 12677
           Summary: Warn when captured const reference (of temorary)
                    becomes stale
           Product: clang
           Version: trunk
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Static Analyzer
        AssignedTo: kremenek at apple.com
        ReportedBy: ggreif at gmail.com
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified


Consider this snippet:

struct Foo {
   const std::vector<int>& v;
   Foo(const std::vector<int>& v) : v(v) {
     // do some preflighting
   }

   ~Foo(void)
   {
     // perform stuff
     do_something_with(v);
   }
};


void bar(int i)
{
    Foo raii(std::vector<int>(1, i));
    // more stuff
}

When the ~Foo() fires at leaving bar(), do_something_with() get called with a
dangling reference to a destructed object. Since Foo's constructor is inline,
clang could observe this behaviour and even warn on it (akin to "returning
reference/pointer to local" warning).

-- 
Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.



More information about the llvm-bugs mailing list