diff options
author | Yitzhak Mandelbaum <yitzhakm@google.com> | 2023-04-14 14:21:41 +0000 |
---|---|---|
committer | Yitzhak Mandelbaum <yitzhakm@google.com> | 2023-04-17 18:02:51 +0000 |
commit | cd22e0dc9d0b5487eb2d54dd028a2aa439627159 (patch) | |
tree | d3664f0512d53ffc72d879814ed411a569ebe187 /clang/unittests | |
parent | 774703ec08f62d702d40e1f97cd35ae5f732c544 (diff) | |
download | llvm-cd22e0dc9d0b5487eb2d54dd028a2aa439627159.tar.gz |
[clang][dataflow] Refine matching of optional types to anchor at top level.
This patch refines the matching of the relevant optional types to anchor on the
global namespace. Previously, we could match anything with the right name
(e.g. `base::Optional`) even if nested within other namespaces. This over
matching resulted in an assertion violation when _different_ `base::Optional`
was encountered nested inside another namespace.
Fixes issue #57036.
Differential Revision: https://reviews.llvm.org/D148344
Diffstat (limited to 'clang/unittests')
-rw-r--r-- | clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp b/clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp index c7e2ad6263f5..8aba91566d4d 100644 --- a/clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp +++ b/clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp @@ -1353,6 +1353,25 @@ INSTANTIATE_TEST_SUITE_P( return Info.param.NamespaceName; }); +// Verifies that similarly-named types are ignored. +TEST_P(UncheckedOptionalAccessTest, NonTrackedOptionalType) { + ExpectDiagnosticsFor( + R"( + namespace other { + namespace $ns { + template <typename T> + struct $optional { + T value(); + }; + } + + void target($ns::$optional<int> opt) { + opt.value(); + } + } + )"); +} + TEST_P(UncheckedOptionalAccessTest, EmptyFunctionBody) { ExpectDiagnosticsFor(R"( void target() { |