aboutsummaryrefslogtreecommitdiff
path: root/test/SemaCXX/conversion-function.cpp
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2008-11-07 20:08:42 +0000
committerDouglas Gregor <dgregor@apple.com>2008-11-07 20:08:42 +0000
commit2f1bc5285ccd40f411af5f5993f013e27e74ab78 (patch)
tree13b6547acb399a89753f742a0595aea613cecc36 /test/SemaCXX/conversion-function.cpp
parent9057a81efaf15c543aab1c5c8488e8a9ed2c0ff4 (diff)
Parsing, ASTs, and semantic analysis for the declaration of conversion
functions in C++, e.g., struct X { operator bool() const; }; Note that these conversions don't actually do anything, since we don't yet have the ability to use them for implicit or explicit conversions. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@58860 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/SemaCXX/conversion-function.cpp')
-rw-r--r--test/SemaCXX/conversion-function.cpp42
1 files changed, 42 insertions, 0 deletions
diff --git a/test/SemaCXX/conversion-function.cpp b/test/SemaCXX/conversion-function.cpp
new file mode 100644
index 0000000000..3c96e54c53
--- /dev/null
+++ b/test/SemaCXX/conversion-function.cpp
@@ -0,0 +1,42 @@
+// RUN: clang -fsyntax-only -verify %s
+class X {
+public:
+ operator bool();
+ operator int() const;
+};
+
+operator int(); // expected-error{{conversion function must be a non-static member function}}
+
+typedef int func_type(int);
+typedef int array_type[10];
+
+class Y {
+public:
+ void operator bool(int, ...) const; // expected-error{{conversion function cannot have a return type}} \
+ // expected-error{{conversion function cannot have any parameters}} \
+ // expected-error{{conversion function cannot be variadic}}
+ operator func_type(); // expected-error{{conversion function cannot convert to a function type}}
+ operator array_type(); // expected-error{{conversion function cannot convert to an array type}}
+};
+
+
+typedef int INT;
+typedef INT* INT_PTR;
+
+class Z {
+ operator int(); // expected-error{{previous declaration is here}}
+ operator int**(); // expected-error{{previous declaration is here}}
+
+ operator INT(); // expected-error{{conversion function cannot be redeclared}}
+ operator INT_PTR*(); // expected-error{{conversion function cannot be redeclared}}
+};
+
+
+class A { };
+
+class B : public A {
+public:
+ operator A&() const; // expected-warning{{conversion function converting 'class B' to its base class 'class A' will never be used}}
+ operator const void() const; // expected-warning{{conversion function converting 'class B' to 'void const' will never be used}}
+ operator const B(); // expected-warning{{conversion function converting 'class B' to itself will never be used}}
+};