jkorous created this revision. jkorous added reviewers: arphaman, vsapsai, dexonsmith, rsmith. jkorous added a project: clang. Herald added subscribers: cfe-commits, mgorny.
It's rather error-prone to leave that member variable uninitialized. The DeclAccessPair seems to be intentionally POD and it seems the make() method is supposed to be called as a constructor. I take DeclAccessPair interface as given so the only options are to either change OverloadCandidate interface or actually initialize the member variable it to some sane default. I suggest the easiest option. Repository: rC Clang https://reviews.llvm.org/D51543 Files: Sema/CMakeLists.txt Sema/OverloadTest.cpp clang/Sema/Overload.h Index: Sema/OverloadTest.cpp =================================================================== --- /dev/null +++ Sema/OverloadTest.cpp @@ -0,0 +1,21 @@ +//=== unittests/Sema/CodeCompleteTest.cpp - Code Complete tests ==============// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "clang/Sema/Overload.h" +#include "gtest/gtest.h" + +namespace { + +TEST(SemaOverloadTest, FoundDeclIsInitializedInOverloadCandidate) { + clang::OverloadCandidate foo; + EXPECT_EQ(foo.FoundDecl.getDecl(), nullptr); + EXPECT_EQ(foo.FoundDecl.getAccess(), clang::AS_none); +} + +} // namespace Index: Sema/CMakeLists.txt =================================================================== --- Sema/CMakeLists.txt +++ Sema/CMakeLists.txt @@ -5,6 +5,7 @@ add_clang_unittest(SemaTests ExternalSemaSourceTest.cpp CodeCompleteTest.cpp + OverloadTest.cpp ) target_link_libraries(SemaTests Index: clang/Sema/Overload.h =================================================================== --- clang/Sema/Overload.h +++ clang/Sema/Overload.h @@ -728,6 +728,11 @@ /// OverloadCandidate - A single candidate in an overload set (C++ 13.3). struct OverloadCandidate { + + OverloadCandidate() + : FoundDecl( DeclAccessPair::make(nullptr, AS_none)) + { } + /// Function - The actual function that this candidate /// represents. When NULL, this is a built-in candidate /// (C++ [over.oper]) or a surrogate for a conversion to a
Index: Sema/OverloadTest.cpp =================================================================== --- /dev/null +++ Sema/OverloadTest.cpp @@ -0,0 +1,21 @@ +//=== unittests/Sema/CodeCompleteTest.cpp - Code Complete tests ==============// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "clang/Sema/Overload.h" +#include "gtest/gtest.h" + +namespace { + +TEST(SemaOverloadTest, FoundDeclIsInitializedInOverloadCandidate) { + clang::OverloadCandidate foo; + EXPECT_EQ(foo.FoundDecl.getDecl(), nullptr); + EXPECT_EQ(foo.FoundDecl.getAccess(), clang::AS_none); +} + +} // namespace Index: Sema/CMakeLists.txt =================================================================== --- Sema/CMakeLists.txt +++ Sema/CMakeLists.txt @@ -5,6 +5,7 @@ add_clang_unittest(SemaTests ExternalSemaSourceTest.cpp CodeCompleteTest.cpp + OverloadTest.cpp ) target_link_libraries(SemaTests Index: clang/Sema/Overload.h =================================================================== --- clang/Sema/Overload.h +++ clang/Sema/Overload.h @@ -728,6 +728,11 @@ /// OverloadCandidate - A single candidate in an overload set (C++ 13.3). struct OverloadCandidate { + + OverloadCandidate() + : FoundDecl( DeclAccessPair::make(nullptr, AS_none)) + { } + /// Function - The actual function that this candidate /// represents. When NULL, this is a built-in candidate /// (C++ [over.oper]) or a surrogate for a conversion to a
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits