From fc63a9f2057525d2b8dac4decf2fcf714f8545a0 Mon Sep 17 00:00:00 2001 From: Javier Lopez-Gomez Date: Mon, 23 Sep 2019 23:23:31 +0200 Subject: [PATCH] DefinitionShadower: added test/CodeUnloading/DeclShadowing.C --- test/CodeUnloading/DeclShadowing.C | 87 ++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 test/CodeUnloading/DeclShadowing.C diff --git a/test/CodeUnloading/DeclShadowing.C b/test/CodeUnloading/DeclShadowing.C new file mode 100644 index 00000000..fcab5a56 --- /dev/null +++ b/test/CodeUnloading/DeclShadowing.C @@ -0,0 +1,87 @@ +//------------------------------------------------------------------------------ +// CLING - the C++ LLVM-based InterpreterG :) +// +// This file is dual-licensed: you can choose to license it under the University +// of Illinois Open Source License or the GNU Lesser General Public License. See +// LICENSE.TXT for details. +//------------------------------------------------------------------------------ + +// RUN: cat %s | %cling 2>&1 | FileCheck %s +#include +#include +#include "cling/Interpreter/Interpreter.h" +cling::runtime::gCling->allowRedefinition(); + +// DefinitionShadower should leave Using{Directive,}Decl untouched. +using namespace std; +using ::strtol; +strtol("0x33", NULL, 0) +//CHECK: (long) 51 + +// ==== Redeclare `i' with a different type +int i = 1 +//CHECK-NEXT: (int) 1 +double i = 3.141592 +//CHECK-NEXT: (double) 3.1415920 + +// ==== Provide different definition for type +struct MyStruct; +struct MyStruct { unsigned u; }; +MyStruct{1111U}.u +//CHECK-NEXT: (unsigned int) 1111 +struct MyStruct { int i, j; } foo{33, 0} +//CHECK-NEXT: (struct MyStruct &) +foo.i +//CHECK-NEXT: (int) 33 +struct MyStruct; // nop +MyStruct{0, 99}.j +//CHECK-NEXT: (int) 99 + +// ==== Make `foo' a typedef type +typedef int foo; +foo bar = 1 +//CHECK-NEXT: (int) 1 +typedef MyStruct foo; +foo{11, 99}.i +//CHECK-NEXT: (int) 11 +bar +// CHECK-NEXT: (int) 1 + +// ==== Give a new defintion for `foo'; test function overload +char foo(int x) { return 'X'; } +int foo() { return 0; } +foo() +//CHECK-NEXT: (int) 0 +foo(0) +//CHECK-NEXT: (char) 'X' +double foo() { return 1; } +foo() +//CHECK-NEXT: (double) 1.0000000 + +// ==== (Re)define a class template +template struct S { T i; }; +S foo{99}; +foo.i +//CHECK-NEXT: (int) 99 +template struct S { T i, j; }; +S{0, 33.0}.j +//CHECK-NEXT: (double) 33.000000 + +// ==== Test function templates +template +typename std::enable_if::value, int>::type f(T x) { return x; } +template +typename std::enable_if::value, int>::type f(T x) { return 0x55aa; } +f(33) +//CHECK-NEXT: (int) 33 +f(3.3f) +//CHECK-NEXT: (int) 21930 + +template +typename std::enable_if::value, int>::type f(T x) { return 0xaa55; } +f(33) +//CHECK-NEXT: (int) 43605 +f(3.3f) +//CHECK-NEXT: (int) 21930 +//expected-no-diagnostics +.q