From 222e2a7620e6520ffaf4fc4e69d79c18da31542e Mon Sep 17 00:00:00 2001 From: "Zancanaro; Carlo" Date: Mon, 24 Sep 2012 09:58:17 +1000 Subject: Add the clang library to the repo (with some of my changes, too). --- clang/test/Sema/parentheses.cpp | 47 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 clang/test/Sema/parentheses.cpp (limited to 'clang/test/Sema/parentheses.cpp') diff --git a/clang/test/Sema/parentheses.cpp b/clang/test/Sema/parentheses.cpp new file mode 100644 index 0000000..7674166 --- /dev/null +++ b/clang/test/Sema/parentheses.cpp @@ -0,0 +1,47 @@ +// RUN: %clang_cc1 -Wparentheses -fsyntax-only -verify %s +// RUN: %clang_cc1 -Wparentheses -fixit %s -o - | %clang_cc1 -Wparentheses -Werror - + +bool someConditionFunc(); + +void conditional_op(int x, int y, bool b) { + (void)(x + someConditionFunc() ? 1 : 2); // expected-warning {{operator '?:' has lower precedence than '+'}} \ + // expected-note {{place parentheses around the '?:' expression to evaluate it first}} \ + // expected-note {{place parentheses around the '+' expression to silence this warning}} + + (void)(x - b ? 1 : 2); // expected-warning {{operator '?:' has lower precedence than '-'}} \ + // expected-note {{place parentheses around the '?:' expression to evaluate it first}} \ + // expected-note {{place parentheses around the '-' expression to silence this warning}} + + (void)(x * (x == y) ? 1 : 2); // expected-warning {{operator '?:' has lower precedence than '*'}} \ + // expected-note {{place parentheses around the '?:' expression to evaluate it first}} \ + // expected-note {{place parentheses around the '*' expression to silence this warning}} +} + +class Stream { +public: + operator int(); + Stream &operator<<(int); + Stream &operator<<(const char*); +}; + +void f(Stream& s, bool b) { + (void)(s << b ? "foo" : "bar"); // expected-warning {{operator '?:' has lower precedence than '<<'}} \ + // expected-note {{place parentheses around the '?:' expression to evaluate it first}} \ + // expected-note {{place parentheses around the '<<' expression to silence this warning}} +} + +struct S { + operator int() { return 42; } + friend S operator+(const S &lhs, bool) { return S(); } +}; + +void test(S *s, bool (S::*m_ptr)()) { + (void)(*s + true ? "foo" : "bar"); // expected-warning {{operator '?:' has lower precedence than '+'}} \ + // expected-note {{place parentheses around the '?:' expression to evaluate it first}} \ + // expected-note {{place parentheses around the '+' expression to silence this warning}} + + (void)((*s + true) ? "foo" : "bar"); // No warning. + + // Don't crash on unusual member call expressions. + (void)((s->*m_ptr)() ? "foo" : "bar"); +} -- cgit v1.2.3