0

I want to use clang-tidy to find out all uncaught exceptions by its direct or indirect caller, up to main, but this demo has no effect. Generally, I want to clang-tidy to report that the function cc is throwing an exception that not being caught by main, but it reports nothing, I want to know why & how can I achieve my goal? Thks

main.cpp

#include <iostream>
int m = 0;
extern int cc() throw();

int ff() {
  if (m > 0) {
    throw "H";
  }
  return 1;
}

int gg() {
  if (m > 0) {
    return ff();
  } else {
    return 1;
  }
}


int main() {
  return cc();
}

cc.cpp

extern int m;
int cc() {
  if (m > 0) {
    return 1;
  }
  throw "D";
}

.clang-tidy

Checks: '-*,bugprone-exception-escape' 
CheckOptions: 
    - key: FunctionsThatShouldNotThrow
      value: main
HeaderFilterRegex: '.*' 

command

clang-tidy main.cpp cc.cpp
1
  • int cc() throw(); (or noexcept in more recent version), so exception of cc doesn"t escape to main. As throw "D"; is uncaught, it would call std::unexpected(). Commented Nov 18, 2021 at 11:47

1 Answer 1

0
  1. it turns out that clang-tidy can not detect cross file checks. If I concatenate the two cpp files, clang-tidy can identify the uncaught exception successfully.
  2. the configuration file for clang-tidy is wrong, the key in CheckOptions should be bugprone-exception-escape.FunctionsThatShouldNotThrow instead of FunctionsThatShouldNotThrow
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.