summaryrefslogtreecommitdiff
path: root/compilerplugins/clang/test/redundantfcast.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'compilerplugins/clang/test/redundantfcast.cxx')
-rw-r--r--compilerplugins/clang/test/redundantfcast.cxx96
1 files changed, 96 insertions, 0 deletions
diff --git a/compilerplugins/clang/test/redundantfcast.cxx b/compilerplugins/clang/test/redundantfcast.cxx
index 985aa8c02994..255c1d44b2a7 100644
--- a/compilerplugins/clang/test/redundantfcast.cxx
+++ b/compilerplugins/clang/test/redundantfcast.cxx
@@ -13,6 +13,7 @@
#include "tools/color.hxx"
#include <functional>
+#include <initializer_list>
#include <memory>
void method1(OUString const&); // expected-note {{in call to method here [loplugin:redundantfcast]}}
@@ -105,4 +106,99 @@ void f2()
}
}
+namespace test7
+{
+// expected-note@+1 6 {{in call to method here [loplugin:redundantfcast]}}
+void f1(std::initializer_list<int> const&);
+// expected-note@+1 6 {{in call to method here [loplugin:redundantfcast]}}
+template <typename T> void f2(std::initializer_list<T> const&);
+// expected-note@+1 4 {{in call to method here [loplugin:redundantfcast]}}
+template <typename T> void f3(T const&);
+// expected-note@+1 4 {{in call to method here [loplugin:redundantfcast]}}
+template <typename... T> void f4(T const&...);
+void f5(int, ...);
+void g(std::initializer_list<int> il)
+{
+ f1(il);
+ f2(il);
+ f3(il);
+ f4(il);
+ f5(0, il);
+ // expected-error@+1 {{redundant functional cast from 'std::initializer_list<int>' to 'std::initializer_list<int>' [loplugin:redundantfcast]}}
+ f1(std::initializer_list<int>(il));
+ // expected-error@+1 {{redundant functional cast from 'std::initializer_list<int>' to 'std::initializer_list<int>' [loplugin:redundantfcast]}}
+ f2(std::initializer_list<int>(il));
+ // expected-error@+1 {{redundant functional cast from 'std::initializer_list<int>' to 'std::initializer_list<int>' [loplugin:redundantfcast]}}
+ f3(std::initializer_list<int>(il));
+ // expected-error@+1 {{redundant functional cast from 'std::initializer_list<int>' to 'std::initializer_list<int>' [loplugin:redundantfcast]}}
+ f4(std::initializer_list<int>(il));
+ // expected-error@+1 {{redundant functional cast from 'std::initializer_list<int>' to 'std::initializer_list<int>' [loplugin:redundantfcast]}}
+ f5(0, std::initializer_list<int>(il));
+ f1({});
+ f1(std::initializer_list<int>{}); // should warn, but not modelled as CXXFunctionalCastExpr
+ // expected-error@+1 {{redundant functional cast from 'std::initializer_list<int>' to 'std::initializer_list<int>' [loplugin:redundantfcast]}}
+ f1(std::initializer_list<int>({}));
+ // f2({}); //error
+ f2(std::initializer_list<int>{}); // should warn, but not modelled as CXXFunctionalCastExpr
+ // expected-error@+1 {{redundant functional cast from 'std::initializer_list<int>' to 'std::initializer_list<int>' [loplugin:redundantfcast]}}
+ f2(std::initializer_list<int>({}));
+ // f3({}); //error
+ f3(std::initializer_list<int>{}); // (not modelled as CXXFunctionalCastExpr anyway)
+ // expected-error@+1 {{redundant functional cast from 'std::initializer_list<int>' to 'std::initializer_list<int>' [loplugin:redundantfcast]}}
+ f3(std::initializer_list<int>({})); // arguably rather subtle, remove "("...")"
+ // f4({}); //error
+ f4(std::initializer_list<int>{}); // (not modelled as CXXFunctionalCastExpr anyway)
+ // expected-error@+1 {{redundant functional cast from 'std::initializer_list<int>' to 'std::initializer_list<int>' [loplugin:redundantfcast]}}
+ f4(std::initializer_list<int>({})); // arguably rather subtle, remove "("...")"
+ // f5(0, {}); //error
+ f5(0, std::initializer_list<int>{}); // (not modelled as CXXFunctionalCastExpr anyway)
+ // expected-error@+1 {{redundant functional cast from 'std::initializer_list<int>' to 'std::initializer_list<int>' [loplugin:redundantfcast]}}
+ f5(0, std::initializer_list<int>({})); // arguably rather subtle, remove "("...")"
+ f1({ 1 });
+ // expected-error@+1 {{redundant functional cast from 'std::initializer_list<int>' to 'std::initializer_list<int>' [loplugin:redundantfcast]}}
+ f1(std::initializer_list<int>{ 1 });
+ // expected-error@+1 {{redundant functional cast from 'std::initializer_list<int>' to 'std::initializer_list<int>' [loplugin:redundantfcast]}}
+ f1(std::initializer_list<int>({ 1 }));
+ f2({ 1 });
+ // expected-error@+1 {{redundant functional cast from 'std::initializer_list<int>' to 'std::initializer_list<int>' [loplugin:redundantfcast]}}
+ f2(std::initializer_list<int>{ 1 });
+ // expected-error@+1 {{redundant functional cast from 'std::initializer_list<int>' to 'std::initializer_list<int>' [loplugin:redundantfcast]}}
+ f2(std::initializer_list<int>({ 1 }));
+ // f3({1}); //error
+ f3(std::initializer_list<int>{ 1 });
+ // expected-error@+1 {{redundant functional cast from 'std::initializer_list<int>' to 'std::initializer_list<int>' [loplugin:redundantfcast]}}
+ f3(std::initializer_list<int>({ 1 })); // arguably rather subtle, remove "("...")"
+ // f4({1}); //error
+ f4(std::initializer_list<int>{ 1 });
+ // expected-error@+1 {{redundant functional cast from 'std::initializer_list<int>' to 'std::initializer_list<int>' [loplugin:redundantfcast]}}
+ f4(std::initializer_list<int>({ 1 })); // arguably rather subtle, remove "("...")"
+ // f5(0, {1}); //error
+ f5(0, std::initializer_list<int>{ 1 });
+ // expected-error@+1 {{redundant functional cast from 'std::initializer_list<int>' to 'std::initializer_list<int>' [loplugin:redundantfcast]}}
+ f5(0, std::initializer_list<int>({ 1 })); // arguably rather subtle, remove "("...")"
+ f1({ 1, 2, 3 });
+ // expected-error@+1 {{redundant functional cast from 'std::initializer_list<int>' to 'std::initializer_list<int>' [loplugin:redundantfcast]}}
+ f1(std::initializer_list<int>{ 1, 2, 3 });
+ // expected-error@+1 {{redundant functional cast from 'std::initializer_list<int>' to 'std::initializer_list<int>' [loplugin:redundantfcast]}}
+ f1(std::initializer_list<int>({ 1, 2, 3 }));
+ f2({ 1, 2, 3 });
+ // expected-error@+1 {{redundant functional cast from 'std::initializer_list<int>' to 'std::initializer_list<int>' [loplugin:redundantfcast]}}
+ f2(std::initializer_list<int>{ 1, 2, 3 });
+ // expected-error@+1 {{redundant functional cast from 'std::initializer_list<int>' to 'std::initializer_list<int>' [loplugin:redundantfcast]}}
+ f2(std::initializer_list<int>({ 1, 2, 3 }));
+ // f3({1, 2, 3}); //error
+ f3(std::initializer_list<int>{ 1, 2, 3 });
+ // expected-error@+1 {{redundant functional cast from 'std::initializer_list<int>' to 'std::initializer_list<int>' [loplugin:redundantfcast]}}
+ f3(std::initializer_list<int>({ 1, 2, 3 })); // arguably rather subtle, remove "("...")"
+ // f4({1, 2, 3}); //error
+ f4(std::initializer_list<int>{ 1, 2, 3 });
+ // expected-error@+1 {{redundant functional cast from 'std::initializer_list<int>' to 'std::initializer_list<int>' [loplugin:redundantfcast]}}
+ f4(std::initializer_list<int>({ 1, 2, 3 })); // arguably rather subtle, remove "("...")"
+ // f5(0, {1, 2, 3}); //error
+ f5(0, std::initializer_list<int>{ 1, 2, 3 });
+ // expected-error@+1 {{redundant functional cast from 'std::initializer_list<int>' to 'std::initializer_list<int>' [loplugin:redundantfcast]}}
+ f5(0, std::initializer_list<int>({ 1, 2, 3 })); // arguably rather subtle, remove "("...")"
+}
+}
+
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */