diff --git a/clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.cpp b/clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.cpp --- a/clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.cpp +++ b/clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.cpp @@ -166,9 +166,11 @@ this); // Comparison to empty string or empty constructor. - const auto WrongComparend = anyOf( - stringLiteral(hasSize(0)), cxxConstructExpr(isDefaultConstruction()), - cxxUnresolvedConstructExpr(argumentCountIs(0))); + const auto WrongComparend = + anyOf(stringLiteral(hasSize(0)), + userDefinedLiteral(hasDescendant(stringLiteral(hasSize(0)))), + cxxConstructExpr(isDefaultConstruction()), + cxxUnresolvedConstructExpr(argumentCountIs(0))); // Match the object being compared. const auto STLArg = anyOf(unaryOperator( diff --git a/clang-tools-extra/test/clang-tidy/checkers/readability/container-size-empty.cpp b/clang-tools-extra/test/clang-tidy/checkers/readability/container-size-empty.cpp --- a/clang-tools-extra/test/clang-tidy/checkers/readability/container-size-empty.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/readability/container-size-empty.cpp @@ -22,6 +22,10 @@ }; } +namespace string_literals{ +string operator""s(const char *, size_t); +} + } template @@ -770,3 +774,17 @@ bool testIgnoredDummyType(const IgnoredDummyType& value) { return value == IgnoredDummyType(); } + +bool testStringLiterals(const std::string& s) +{ + using namespace std::string_literals; + return s == ""s; + // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: the 'empty' method should be used + // CHECK-FIXES: {{^ }}return s.empty() +} + +bool testNotEmptyStringLiterals(const std::string& s) +{ + using namespace std::string_literals; + return s == "foo"s; +} \ No newline at end of file