brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.2 KiB · df7689f Raw
66 lines · cpp
1// RUN: %clang_cc1 -fsyntax-only -fcxx-exceptions -fexceptions -Wreturn-type -Winvalid-noreturn -verify %s2// expected-no-diagnostics3 4namespace std {5  class string {6  public:7    string(const char*); // constructor for runtime_error8  };9  class runtime_error {10  public:11    runtime_error(const string &); 12  };13}14 15// Non-template version.16 17void throwError(const std::string& msg) {18  throw std::runtime_error(msg);19}20 21int ensureZero(const int i) {22  if (i == 0) return 0;23  throwError("ERROR"); // no-warning24}25 26int alwaysThrows() {27  throw std::runtime_error("This function always throws"); // no-warning28}29 30// Template version.31 32template<typename T> 33void throwErrorTemplate(const T& msg) {34  throw msg;35}36 37template <typename T>38int ensureZeroTemplate(T i) {39  if (i == 0) return 0;40  throwErrorTemplate("ERROR"); // no-warning41}42 43void testTemplates() {44  throwErrorTemplate("ERROR");45  (void)ensureZeroTemplate(42);46}47 48// Ensure that explicit specialization of a member function does not inherit49// the warning from the primary template.50 51template<typename T>52struct S {53  void f();54  void g();55};56 57template<typename T>58void S<T>::f() { throw 0; } 59template<>60void S<int>::f() {}61 62template<typename T> 63void S<T>::g() {}  64template<> 65void S<int>::g() { throw 0; }66