Skip to content

Ensure functions are anchored in the global namespace #99084

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 17, 2024

Conversation

matthew-f
Copy link
Contributor

The regular expressions match functions that aren't anchored in the global namespace. For example ::connect matches QObject::connect This change is to remove these false positives

Copy link

Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be
notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this page.

If this is not working for you, it is probably because you do not have write
permissions for the repository. In which case you can instead tag reviewers by
name in a comment by using @ followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review
by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate
is once a week. Please remember that you are asking for valuable time from other developers.

If you have further questions, they may be answered by the LLVM GitHub User Guide.

You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums.

@llvmbot
Copy link
Member

llvmbot commented Jul 16, 2024

@llvm/pr-subscribers-clang-tidy

@llvm/pr-subscribers-clang-tools-extra

Author: None (matthew-f)

Changes

The regular expressions match functions that aren't anchored in the global namespace. For example ::connect matches QObject::connect This change is to remove these false positives


Full diff: https://github.com/llvm/llvm-project/pull/99084.diff

1 Files Affected:

  • (modified) clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.cpp (+89-89)
diff --git a/clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.cpp
index 73373147e96fc..955a9b94dfaf6 100644
--- a/clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.cpp
@@ -48,97 +48,97 @@ UnusedReturnValueCheck::UnusedReturnValueCheck(llvm::StringRef Name,
                                                ClangTidyContext *Context)
     : ClangTidyCheck(Name, Context),
       CheckedFunctions(utils::options::parseStringList(
-          Options.get("CheckedFunctions", "::std::async$;"
-                                          "::std::launder$;"
-                                          "::std::remove$;"
-                                          "::std::remove_if$;"
-                                          "::std::unique$;"
-                                          "::std::unique_ptr::release$;"
-                                          "::std::basic_string::empty$;"
-                                          "::std::vector::empty$;"
-                                          "::std::back_inserter$;"
-                                          "::std::distance$;"
-                                          "::std::find$;"
-                                          "::std::find_if$;"
-                                          "::std::inserter$;"
-                                          "::std::lower_bound$;"
-                                          "::std::make_pair$;"
-                                          "::std::map::count$;"
-                                          "::std::map::find$;"
-                                          "::std::map::lower_bound$;"
-                                          "::std::multimap::equal_range$;"
-                                          "::std::multimap::upper_bound$;"
-                                          "::std::set::count$;"
-                                          "::std::set::find$;"
-                                          "::std::setfill$;"
-                                          "::std::setprecision$;"
-                                          "::std::setw$;"
-                                          "::std::upper_bound$;"
-                                          "::std::vector::at$;"
+          Options.get("CheckedFunctions", "^::std::async$;"
+                                          "^::std::launder$;"
+                                          "^::std::remove$;"
+                                          "^::std::remove_if$;"
+                                          "^::std::unique$;"
+                                          "^::std::unique_ptr::release$;"
+                                          "^::std::basic_string::empty$;"
+                                          "^::std::vector::empty$;"
+                                          "^::std::back_inserter$;"
+                                          "^::std::distance$;"
+                                          "^::std::find$;"
+                                          "^::std::find_if$;"
+                                          "^::std::inserter$;"
+                                          "^::std::lower_bound$;"
+                                          "^::std::make_pair$;"
+                                          "^::std::map::count$;"
+                                          "^::std::map::find$;"
+                                          "^::std::map::lower_bound$;"
+                                          "^::std::multimap::equal_range$;"
+                                          "^::std::multimap::upper_bound$;"
+                                          "^::std::set::count$;"
+                                          "^::std::set::find$;"
+                                          "^::std::setfill$;"
+                                          "^::std::setprecision$;"
+                                          "^::std::setw$;"
+                                          "^::std::upper_bound$;"
+                                          "^::std::vector::at$;"
                                           // C standard library
-                                          "::bsearch$;"
-                                          "::ferror$;"
-                                          "::feof$;"
-                                          "::isalnum$;"
-                                          "::isalpha$;"
-                                          "::isblank$;"
-                                          "::iscntrl$;"
-                                          "::isdigit$;"
-                                          "::isgraph$;"
-                                          "::islower$;"
-                                          "::isprint$;"
-                                          "::ispunct$;"
-                                          "::isspace$;"
-                                          "::isupper$;"
-                                          "::iswalnum$;"
-                                          "::iswprint$;"
-                                          "::iswspace$;"
-                                          "::isxdigit$;"
-                                          "::memchr$;"
-                                          "::memcmp$;"
-                                          "::strcmp$;"
-                                          "::strcoll$;"
-                                          "::strncmp$;"
-                                          "::strpbrk$;"
-                                          "::strrchr$;"
-                                          "::strspn$;"
-                                          "::strstr$;"
-                                          "::wcscmp$;"
+                                          "^::bsearch$;"
+                                          "^::ferror$;"
+                                          "^::feof$;"
+                                          "^::isalnum$;"
+                                          "^::isalpha$;"
+                                          "^::isblank$;"
+                                          "^::iscntrl$;"
+                                          "^::isdigit$;"
+                                          "^::isgraph$;"
+                                          "^::islower$;"
+                                          "^::isprint$;"
+                                          "^::ispunct$;"
+                                          "^::isspace$;"
+                                          "^::isupper$;"
+                                          "^::iswalnum$;"
+                                          "^::iswprint$;"
+                                          "^::iswspace$;"
+                                          "^::isxdigit$;"
+                                          "^::memchr$;"
+                                          "^::memcmp$;"
+                                          "^::strcmp$;"
+                                          "^::strcoll$;"
+                                          "^::strncmp$;"
+                                          "^::strpbrk$;"
+                                          "^::strrchr$;"
+                                          "^::strspn$;"
+                                          "^::strstr$;"
+                                          "^::wcscmp$;"
                                           // POSIX
-                                          "::access$;"
-                                          "::bind$;"
-                                          "::connect$;"
-                                          "::difftime$;"
-                                          "::dlsym$;"
-                                          "::fnmatch$;"
-                                          "::getaddrinfo$;"
-                                          "::getopt$;"
-                                          "::htonl$;"
-                                          "::htons$;"
-                                          "::iconv_open$;"
-                                          "::inet_addr$;"
-                                          "::isascii$;"
-                                          "::isatty$;"
-                                          "::mmap$;"
-                                          "::newlocale$;"
-                                          "::openat$;"
-                                          "::pathconf$;"
-                                          "::pthread_equal$;"
-                                          "::pthread_getspecific$;"
-                                          "::pthread_mutex_trylock$;"
-                                          "::readdir$;"
-                                          "::readlink$;"
-                                          "::recvmsg$;"
-                                          "::regexec$;"
-                                          "::scandir$;"
-                                          "::semget$;"
-                                          "::setjmp$;"
-                                          "::shm_open$;"
-                                          "::shmget$;"
-                                          "::sigismember$;"
-                                          "::strcasecmp$;"
-                                          "::strsignal$;"
-                                          "::ttyname"))),
+                                          "^::access$;"
+                                          "^::bind$;"
+                                          "^::connect$;"
+                                          "^::difftime$;"
+                                          "^::dlsym$;"
+                                          "^::fnmatch$;"
+                                          "^::getaddrinfo$;"
+                                          "^::getopt$;"
+                                          "^::htonl$;"
+                                          "^::htons$;"
+                                          "^::iconv_open$;"
+                                          "^::inet_addr$;"
+                                          "^::isascii$;"
+                                          "^::isatty$;"
+                                          "^::mmap$;"
+                                          "^::newlocale$;"
+                                          "^::openat$;"
+                                          "^::pathconf$;"
+                                          "^::pthread_equal$;"
+                                          "^::pthread_getspecific$;"
+                                          "^::pthread_mutex_trylock$;"
+                                          "^::readdir$;"
+                                          "^::readlink$;"
+                                          "^::recvmsg$;"
+                                          "^::regexec$;"
+                                          "^::scandir$;"
+                                          "^::semget$;"
+                                          "^::setjmp$;"
+                                          "^::shm_open$;"
+                                          "^::shmget$;"
+                                          "^::sigismember$;"
+                                          "^::strcasecmp$;"
+                                          "^::strsignal$;"
+                                          "^::ttyname"))),
       CheckedReturnTypes(utils::options::parseStringList(
           Options.get("CheckedReturnTypes", "::std::error_code$;"
                                             "::std::error_condition$;"

@PiotrZSL PiotrZSL merged commit c736ca8 into llvm:main Jul 17, 2024
8 checks passed
Copy link

@matthew-f Congratulations on having your first Pull Request (PR) merged into the LLVM Project!

Your changes will be combined with recent changes from other authors, then tested
by our build bots. If there is a problem with a build, you may receive a report in an email or a comment on this PR.

Please check whether problems have been caused by your change specifically, as
the builds can include changes from many authors. It is not uncommon for your
change to be included in a build that fails due to someone else's changes, or
infrastructure issues.

How to do this, and the rest of the post-merge process, is covered in detail here.

If your change does cause a problem, it may be reverted, or you can revert it yourself.
This is a normal part of LLVM development. You can fix your changes and open a new PR to merge them again.

If you don't get any reports, no action is required from you. Your changes are working as expected, well done!

@njames93
Copy link
Member

Just a drive by comment, would it not have been nicer to use the hasAnyName matcher which understands :: at the start means global namespace.

@PiotrZSL
Copy link
Member

Just a drive by comment, would it not have been nicer to use the hasAnyName matcher which understands :: at the start means global namespace.

Support for regexp were added in #82952, as it were requested, so no more hasAnyName.

@matthew-f I think documentation also need same fix.

PiotrZSL added a commit that referenced this pull request Jul 18, 2024
Update documentation, and correct configuration
yuxuanchen1997 pushed a commit that referenced this pull request Jul 25, 2024
…99084)

Summary:
The regular expressions match functions that aren't anchored in the
global namespace. For example `::connect` matches `QObject::connect`
This change is to remove these false positives

Test Plan: 

Reviewers: 

Subscribers: 

Tasks: 

Tags: 


Differential Revision: https://phabricator.intern.facebook.com/D60251713
yuxuanchen1997 pushed a commit that referenced this pull request Jul 25, 2024
Summary: Update documentation, and correct configuration

Test Plan: 

Reviewers: 

Subscribers: 

Tasks: 

Tags: 


Differential Revision: https://phabricator.intern.facebook.com/D60251646
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants