Skip to content

readability-redundant-smartptr-get doesnt't flag VS2017 STL smart pointers #36696

@llvmbot

Description

@llvmbot
Bugzilla Link 37348
Version unspecified
OS Windows NT
Reporter LLVM Bugzilla Contributor
CC @EugeneZelenko

Extended Description

When using clang-tidy on a Visual Studio 2017 codebase together with the VS2017 STL, readability-redundant-smartptr-get doesn't recognize std::shared_ptr as smart pointer and thus doesn't flag anything.

This seems to be caused by the QuacksLikeASmartptr matcher, which expects any smart pointer to have a operator-> and operator* method:

const auto QuacksLikeASmartptr = recordDecl(
    recordDecl().bind("duck_typing"),
    has(cxxMethodDecl(hasName("operator->"),
                      returns(qualType(pointsTo(type().bind("op->Type")))))),
    has(cxxMethodDecl(hasName("operator*"), returns(qualType(references(
                                                type().bind("op*Type")))))));

The VS2017 std::shared_ptr defines these operators as method templates and is thus not matched:

template<class _Ty2 = _Ty,
  enable_if_t<!disjunction_v<is_array<_Ty2>, is_void<_Ty2>>, int> = 0>
  _NODISCARD _Ty2& operator*() const _NOEXCEPT

template<class _Ty2 = _Ty,
  enable_if_t<!is_array_v<_Ty2>, int> = 0>
  _NODISCARD _Ty2 * operator->() const _NOEXCEPT

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugzillaIssues migrated from bugzillaclang-tidyenhancementImproving things as opposed to bug fixing, e.g. new or missing feature

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions