Closed
Description
Describe the bug
cppfront is emitting the explicit
specifier on all single argument constructors including move and copy constructors. At the same time implicit move and copy are being used by code that is emitted - for instance - when returning named values from functions.
To Reproduce
Steps to reproduce the behavior:
- Sample code - distilled down to minimal essentials please
Here is a Compiler Explorer link demonstrating the problem: https://godbolt.org/z/x8T4ec7Wd
Note howfoo
's move and copy constructors are explicit, but the call toget_foo()
inmain
would need at least an implicit copy constructor. - Command lines including which C++ compiler you are using
Calling cppfront with -p and compiling the result with gcc-12 - Expected result - what you expected to happen
I would expect copy and move constructors to not beexplicit
- Actual result/error6.
Copy and move constructors are markedexplicit
Additional context
I have resolved this issue locally by only emitting the explicit
specifier if the constructor does not have a that
:
diff --git a/source/cppfront.cpp b/source/cppfront.cpp
index 570c078..e4e2a04 100644
--- a/source/cppfront.cpp
+++ b/source/cppfront.cpp
@@ -5139,6 +5139,7 @@ public:
break;default:
if (
func->is_constructor()
+ && !func->is_constructor_with_that()
&& func->parameters->ssize() == 2
&& generating_assignment_from != &n
)