aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/gdc.dg
diff options
context:
space:
mode:
authorIain Buclaw <ibuclaw@gdcproject.org>2021-07-26 19:34:33 +0200
committerIain Buclaw <ibuclaw@gdcproject.org>2021-07-29 17:10:09 +0200
commit7616ed6307c90b5bbf1bf53550d33cc674ab4b6f (patch)
tree54b64dfacbd3bd53468ab91c176a033cb390383a /gcc/testsuite/gdc.dg
parent5c9b7408dc578cb2ae142a5c1b724c183497bdb2 (diff)
downloadgcc-7616ed6307c90b5bbf1bf53550d33cc674ab4b6f.zip
gcc-7616ed6307c90b5bbf1bf53550d33cc674ab4b6f.tar.gz
gcc-7616ed6307c90b5bbf1bf53550d33cc674ab4b6f.tar.bz2
d: Return the correct value for C++ constructor calls (PR101664)
C++ constructors return void, even though the front-end semantic treats them as implicitly returning `this'. To handle this correctly, the object reference is cached and used as the result of the expression. PR d/101664 gcc/d/ChangeLog: * expr.cc (ExprVisitor::visit (CallExp *)): Use object expression as result for C++ constructor calls. gcc/testsuite/ChangeLog: * gdc.dg/extern-c++/extern-c++.exp: New. * gdc.dg/extern-c++/pr101664.d: New test. * gdc.dg/extern-c++/pr101664_1.cc: New test.
Diffstat (limited to 'gcc/testsuite/gdc.dg')
-rw-r--r--gcc/testsuite/gdc.dg/extern-c++/extern-c++.exp39
-rw-r--r--gcc/testsuite/gdc.dg/extern-c++/pr101664.d15
-rw-r--r--gcc/testsuite/gdc.dg/extern-c++/pr101664_1.cc10
3 files changed, 64 insertions, 0 deletions
diff --git a/gcc/testsuite/gdc.dg/extern-c++/extern-c++.exp b/gcc/testsuite/gdc.dg/extern-c++/extern-c++.exp
new file mode 100644
index 0000000..d38f993
--- /dev/null
+++ b/gcc/testsuite/gdc.dg/extern-c++/extern-c++.exp
@@ -0,0 +1,39 @@
+# Copyright (C) 2021 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GCC; see the file COPYING3. If not see
+# <http://www.gnu.org/licenses/>.
+
+# Load support procs.
+load_lib gdc-dg.exp
+
+# We are mixing D and C++ code, need to pull in libstdc++
+global GDC_INCLUDE_CXX_FLAGS
+set GDC_INCLUDE_CXX_FLAGS 1
+
+# Initialize `dg'.
+dg-init
+
+# Main loop.
+if [check_no_compiler_messages extern_c++_tests assembly {
+ // C++
+ int main() { return 0; }
+}] {
+ gdc-dg-runtest [lsort \
+ [glob -nocomplain $srcdir/$subdir/*.d ] ] "" ""
+}
+
+set GDC_INCLUDE_CXX_FLAGS 0
+
+# All done.
+dg-finish
diff --git a/gcc/testsuite/gdc.dg/extern-c++/pr101664.d b/gcc/testsuite/gdc.dg/extern-c++/pr101664.d
new file mode 100644
index 0000000..57b3d90
--- /dev/null
+++ b/gcc/testsuite/gdc.dg/extern-c++/pr101664.d
@@ -0,0 +1,15 @@
+// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101664
+// { dg-do run }
+// { dg-options "-O2" }
+// { dg-additional-sources "pr101664_1.cc" }
+
+extern(C++) struct S101664
+{
+ int i;
+ this(int);
+}
+
+void main()
+{
+ assert(S101664(1).i == 1);
+}
diff --git a/gcc/testsuite/gdc.dg/extern-c++/pr101664_1.cc b/gcc/testsuite/gdc.dg/extern-c++/pr101664_1.cc
new file mode 100644
index 0000000..066e784
--- /dev/null
+++ b/gcc/testsuite/gdc.dg/extern-c++/pr101664_1.cc
@@ -0,0 +1,10 @@
+struct S101664
+{
+ int i;
+ S101664 (int n);
+};
+
+S101664::S101664 (int n)
+ : i(n)
+{
+}