summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorErich Keane <erich.keane@intel.com>2017-09-28 20:36:53 +0000
committerErich Keane <erich.keane@intel.com>2017-09-28 20:36:53 +0000
commitde3f99f1ef73aba46c4010116ef239c47bd26c94 (patch)
treecca93ab8bdd9e26c6a6599538824358e14bbd471 /test
parent112bfcc8447b712c672f76c5d70a64882ecae258 (diff)
downloadclang-de3f99f1ef73aba46c4010116ef239c47bd26c94.tar.gz
[Sema] Warn on attribute nothrow conflicting with language specifiers
I discovered it was possible to create a 'nothrow' noexcept(false) function, which is both non-sensical as well as seemingly breaking. This patch warns if attribute nothrow is used with anything besides "noexcept". "noexcept(true)" isn't possible, because the noexcept decl isn't parsed until later. Differential Revision: https://reviews.llvm.org/D38205 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@314461 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test')
-rw-r--r--test/SemaCXX/warn-conflicting-nothrow-attr-exception-spec.cpp24
1 files changed, 24 insertions, 0 deletions
diff --git a/test/SemaCXX/warn-conflicting-nothrow-attr-exception-spec.cpp b/test/SemaCXX/warn-conflicting-nothrow-attr-exception-spec.cpp
new file mode 100644
index 0000000000..c927c4f926
--- /dev/null
+++ b/test/SemaCXX/warn-conflicting-nothrow-attr-exception-spec.cpp
@@ -0,0 +1,24 @@
+// RUN: %clang_cc1 %s -fcxx-exceptions -fsyntax-only -Wexceptions -verify -std=c++14
+
+struct S {
+ //expected-warning@+2 {{attribute 'nothrow' ignored due to conflicting exception specification}}
+ //expected-note@+1 {{exception specification declared here}}
+ __attribute__((nothrow)) S() noexcept(true);
+ //expected-warning@+2 {{attribute 'nothrow' ignored due to conflicting exception specification}}
+ //expected-note@+1 {{exception specification declared here}}
+ __attribute__((nothrow)) void Func1() noexcept(false);
+ __attribute__((nothrow)) void Func3() noexcept;
+};
+
+void throwing() noexcept(false);
+void non_throwing(bool b = true) noexcept;
+
+template <typename Fn>
+struct T {
+ __attribute__((nothrow)) void f(Fn) noexcept(Fn());
+};
+
+//expected-warning@-3 {{attribute 'nothrow' ignored due to conflicting exception specification}}
+//expected-note@-4 {{exception specification declared here}}
+template struct T<decltype(throwing)>;
+template struct T<decltype(non_throwing)>;