Skip to content

Commit

Permalink
Merge pull request #594 from andreasfertig/fixIssue593
Browse files Browse the repository at this point in the history
Fixed #593: Don't show casts for user defined conversions.
  • Loading branch information
andreasfertig authored Oct 19, 2023
2 parents 0d8ad30 + baa5b4a commit 17b84a8
Show file tree
Hide file tree
Showing 42 changed files with 100 additions and 85 deletions.
1 change: 0 additions & 1 deletion .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ]
# Priority: 3
# - Regex: '.*'
# Priority: 1
SortIncludes: false
IncludeCategories:
- Regex: '^<.*\.h>'
Priority: 1
Expand Down
5 changes: 3 additions & 2 deletions CodeGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1768,8 +1768,9 @@ void CodeGenerator::InsertArg(const ImplicitCastExpr* stmt)
case CastKind::CK_PointerToIntegral: [[fallthrough]];
case CastKind::CK_BitCast: [[fallthrough]];
case CastKind::CK_UncheckedDerivedToBase: [[fallthrough]];
case CastKind::CK_ToUnion: [[fallthrough]];
case CastKind::CK_UserDefinedConversion: [[fallthrough]];
case CastKind::CK_ToUnion:
[[fallthrough]];
// case CastKind::CK_UserDefinedConversion: [[fallthrough]];
case CastKind::CK_AtomicToNonAtomic: [[fallthrough]];
case CastKind::CK_DerivedToBase: [[fallthrough]];
case CastKind::CK_FloatingCast: [[fallthrough]];
Expand Down
38 changes: 19 additions & 19 deletions tests/CharLiteralTest.expect
Original file line number Diff line number Diff line change
Expand Up @@ -89,25 +89,25 @@ class Test
inline void Apply()
{
Foo<char> * data = this->mData;
data[static_cast<int>(this->GetLength().operator int()) + 1].operator=('\0');
data[static_cast<int>(this->GetLength().operator int()) + 1].operator=('\n');
data[static_cast<int>(this->GetLength().operator int()) + 1].operator=('\\');
data[static_cast<int>(this->GetLength().operator int()) + 1].operator=('\'');
data[static_cast<int>(this->GetLength().operator int()) + 1].operator=('\a');
data[static_cast<int>(this->GetLength().operator int()) + 1].operator=('\b');
data[static_cast<int>(this->GetLength().operator int()) + 1].operator=('\f');
data[static_cast<int>(this->GetLength().operator int()) + 1].operator=('\r');
data[static_cast<int>(this->GetLength().operator int()) + 1].operator=('\t');
data[static_cast<int>(this->GetLength().operator int()) + 1].operator=('\v');
data[static_cast<int>(this->GetLength().operator int()) + 1].operator=(static_cast<char>(L'\n'));
data[static_cast<int>(this->GetLength().operator int()) + 1].operator=(u8'\n');
data[static_cast<int>(this->GetLength().operator int()) + 1].operator=(static_cast<char>(u'\n'));
data[static_cast<int>(this->GetLength().operator int()) + 1].operator=(static_cast<char>(U'\n'));
data[static_cast<int>(this->GetLength().operator int()) + 1].operator=(3U);
data[static_cast<int>(this->GetLength().operator int()) + 1].operator=(3UL);
data[static_cast<int>(this->GetLength().operator int()) + 1].operator=(3ULL);
data[static_cast<int>(this->GetLength().operator int()) + 1].operator=(3LL);
data[static_cast<int>(this->GetLength().operator int()) + 1].operator=(3L);
data[this->GetLength().operator int() + 1].operator=('\0');
data[this->GetLength().operator int() + 1].operator=('\n');
data[this->GetLength().operator int() + 1].operator=('\\');
data[this->GetLength().operator int() + 1].operator=('\'');
data[this->GetLength().operator int() + 1].operator=('\a');
data[this->GetLength().operator int() + 1].operator=('\b');
data[this->GetLength().operator int() + 1].operator=('\f');
data[this->GetLength().operator int() + 1].operator=('\r');
data[this->GetLength().operator int() + 1].operator=('\t');
data[this->GetLength().operator int() + 1].operator=('\v');
data[this->GetLength().operator int() + 1].operator=(static_cast<char>(L'\n'));
data[this->GetLength().operator int() + 1].operator=(u8'\n');
data[this->GetLength().operator int() + 1].operator=(static_cast<char>(u'\n'));
data[this->GetLength().operator int() + 1].operator=(static_cast<char>(U'\n'));
data[this->GetLength().operator int() + 1].operator=(3U);
data[this->GetLength().operator int() + 1].operator=(3UL);
data[this->GetLength().operator int() + 1].operator=(3ULL);
data[this->GetLength().operator int() + 1].operator=(3LL);
data[this->GetLength().operator int() + 1].operator=(3L);
}

inline Foo<int> GetLength() const
Expand Down
4 changes: 2 additions & 2 deletions tests/Class2Test.expect
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class Test
{
Test tmp = Test(*this) /* NRVO variable */;
this->operator++();
return Test(static_cast<int>(static_cast<Test &&>(tmp).operator int()));
return Test(static_cast<Test &&>(tmp).operator int());
}

inline Test & operator+=(const Test & rhs)
Expand Down Expand Up @@ -72,7 +72,7 @@ int main()
s.count.operator++(0);
Test t = Test();
char * raw = reinterpret_cast<char *>(&s + 1);
Test * p = reinterpret_cast<Test *>(&raw[static_cast<int>(s.count.operator int())]);
Test * p = reinterpret_cast<Test *>(&raw[s.count.operator int()]);
(*p).operator=((t));
(*p).operator=(s2.count);
s.count.operator+=(Test(static_cast<int>(sizeof(p))));
Expand Down
4 changes: 2 additions & 2 deletions tests/ClassTest.expect
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class Test
{
Test tmp = Test(*this) /* NRVO variable */;
this->operator++();
return Test(static_cast<int>(static_cast<Test &&>(tmp).operator int()));
return Test(static_cast<Test &&>(tmp).operator int());
}

inline Test & operator+=(const Test & rhs)
Expand All @@ -55,7 +55,7 @@ int main()
Test t = Test(2);
t.operator=(Test(3 * 2));
Test tt = Test(4);
t.operator+=(Test(static_cast<int>(tt.operator int()) * 2));
t.operator+=(Test(tt.operator int() * 2));
return 0;
}

Expand Down
2 changes: 1 addition & 1 deletion tests/ConversionDeclTest.expect
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ namespace test
int main()
{
test::coroutine_handle<int> a = {};
test::coroutine_handle<void> b = static_cast<test::coroutine_handle<void>>(a.operator test::coroutine_handle<void>());
test::coroutine_handle<void> b = a.operator test::coroutine_handle<void>();
return 0;
}

Expand Down
2 changes: 1 addition & 1 deletion tests/CoroutinesCoReturnPlusTest.expect
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ struct generator

inline ~generator() noexcept
{
if(static_cast<bool>(this->p.operator bool())) {
if(this->p.operator bool()) {
this->p.destroy();
}

Expand Down
2 changes: 1 addition & 1 deletion tests/EduCoroutineAllocFailureTest.expect
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ struct generator<int>

inline ~generator() noexcept
{
if(static_cast<bool>(this->p.operator bool())) {
if(this->p.operator bool()) {
this->p.destroy();
}

Expand Down
2 changes: 1 addition & 1 deletion tests/EduCoroutineBinaryExprTest.expect
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ struct generator

inline ~generator() noexcept
{
if(static_cast<bool>(this->p.operator bool())) {
if(this->p.operator bool()) {
this->p.destroy();
}

Expand Down
2 changes: 1 addition & 1 deletion tests/EduCoroutineCaptureConstTest.expect
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ struct generator

inline ~generator() noexcept
{
if(static_cast<bool>(this->p.operator bool())) {
if(this->p.operator bool()) {
this->p.destroy();
}

Expand Down
2 changes: 1 addition & 1 deletion tests/EduCoroutineCaptureThisTest.expect
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ struct my_resumable

inline ~my_resumable() noexcept
{
if(static_cast<bool>(this->m_handle.operator bool())) {
if(this->m_handle.operator bool()) {
this->m_handle.destroy();
}

Expand Down
2 changes: 1 addition & 1 deletion tests/EduCoroutineCoreturnWithCoawaitTest.expect
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ struct generator

inline ~generator() noexcept
{
if(static_cast<bool>(this->p.operator bool())) {
if(this->p.operator bool()) {
this->p.destroy();
}

Expand Down
2 changes: 1 addition & 1 deletion tests/EduCoroutineCustomYieldTypeTest.expect
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ struct generator

inline ~generator() noexcept
{
if(static_cast<bool>(this->p.operator bool())) {
if(this->p.operator bool()) {
this->p.destroy();
}

Expand Down
6 changes: 3 additions & 3 deletions tests/EduCoroutineExprTest.expect
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ struct task
if(previous) {
return previous;
} else {
return static_cast<std::coroutine_handle<void>>(std::noop_coroutine().operator std::coroutine_handle<void>());
return std::noop_coroutine().operator std::coroutine_handle<void>();
}

}
Expand Down Expand Up @@ -154,10 +154,10 @@ struct task<int>
{
{
std::coroutine_handle<void> previous = std::coroutine_handle<void>(h.promise().previous);
if(static_cast<bool>(previous.operator bool())) {
if(previous.operator bool()) {
return std::coroutine_handle<void>(static_cast<std::coroutine_handle<void> &&>(previous));
} else {
return static_cast<std::coroutine_handle<void>>(std::noop_coroutine().operator std::coroutine_handle<void>());
return std::noop_coroutine().operator std::coroutine_handle<void>();
}

}
Expand Down
2 changes: 1 addition & 1 deletion tests/EduCoroutineSimpleTest.expect
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ struct generator

inline ~generator() noexcept
{
if(static_cast<bool>(this->p.operator bool())) {
if(this->p.operator bool()) {
this->p.destroy();
}

Expand Down
2 changes: 1 addition & 1 deletion tests/EduCoroutineSuspendNeverBoolTest.expect
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ struct generator<int>

inline ~generator() noexcept
{
if(static_cast<bool>(this->p.operator bool())) {
if(this->p.operator bool()) {
this->p.destroy();
}

Expand Down
2 changes: 1 addition & 1 deletion tests/EduCoroutineSuspendNeverTest.expect
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ struct generator<int>

inline ~generator() noexcept
{
if(static_cast<bool>(this->p.operator bool())) {
if(this->p.operator bool()) {
this->p.destroy();
}

Expand Down
2 changes: 1 addition & 1 deletion tests/EduCoroutineTemplateGeneratorTest.expect
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ struct generator<int>

inline ~generator() noexcept
{
if(static_cast<bool>(this->p.operator bool())) {
if(this->p.operator bool()) {
this->p.destroy();
}

Expand Down
2 changes: 1 addition & 1 deletion tests/EduCoroutineVoidTest.expect
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ struct generator<int>

inline ~generator() noexcept
{
if(static_cast<bool>(this->p.operator bool())) {
if(this->p.operator bool()) {
this->p.destroy();
}

Expand Down
2 changes: 1 addition & 1 deletion tests/EduCoroutineWithDtorTest.expect
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ struct generator<Test>

inline ~generator() noexcept
{
if(static_cast<bool>(this->p.operator bool())) {
if(this->p.operator bool()) {
this->p.destroy();
}

Expand Down
2 changes: 1 addition & 1 deletion tests/EduCoroutineWithExceptionHandlerTest.expect
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ struct generator<int>

inline ~generator() noexcept
{
if(static_cast<bool>(this->p.operator bool())) {
if(this->p.operator bool()) {
this->p.destroy();
}

Expand Down
2 changes: 1 addition & 1 deletion tests/EduCoroutineWithLambdaTest.expect
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ struct generator

inline ~generator() noexcept
{
if(static_cast<bool>(this->p.operator bool())) {
if(this->p.operator bool()) {
this->p.destroy();
}

Expand Down
2 changes: 1 addition & 1 deletion tests/IfSwitchInitHandler5Test.expect
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ int main()
std::weak_ptr<int> weakPtr = std::weak_ptr<int>(sharedPtr, 0);
{
std::shared_ptr<int> sharedPtr1 = weakPtr.lock();
if(static_cast<bool>(sharedPtr1.operator bool())) {
if(sharedPtr1.operator bool()) {
std::operator<<(std::cout, "*sharedPtr: ").operator<<(sharedPtr.operator*()).operator<<(std::endl);
} else {
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Issue324.expect
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ Str globalString = Str("test");

const char * getString(bool empty)
{
return static_cast<const char *>((empty ? Str("") : Str(globalString)).operator const char *());
return (empty ? Str("") : Str(globalString)).operator const char *();
}

4 changes: 2 additions & 2 deletions tests/Issue467.expect
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ int main()
l.operator()();
l.operator()();
l.operator()();
(+static_cast<void (*)()>(l.operator __lambda_5_14::retType_5_14()))();
(+static_cast<void (*)()>(l.operator __lambda_5_14::retType_5_14()))();
(+l.operator __lambda_5_14::retType_5_14())();
(+l.operator __lambda_5_14::retType_5_14())();
return 0;
}

2 changes: 1 addition & 1 deletion tests/Issue491.expect
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,5 @@ class __lambda_1_10

};

__lambda_1_10 x = __lambda_1_10{+static_cast<void (*)()>(__lambda_1_16{}.operator __lambda_1_16::retType_1_16())};
__lambda_1_10 x = __lambda_1_10{+__lambda_1_16{}.operator __lambda_1_16::retType_1_16()};

6 changes: 3 additions & 3 deletions tests/Issue518.expect
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ struct task
if(previous) {
return previous;
} else {
return static_cast<std::coroutine_handle<void>>(std::noop_coroutine().operator std::coroutine_handle<void>());
return std::noop_coroutine().operator std::coroutine_handle<void>();
}

}
Expand Down Expand Up @@ -154,10 +154,10 @@ struct task<int>
{
{
std::coroutine_handle<void> previous = std::coroutine_handle<void>(h.promise().previous);
if(static_cast<bool>(previous.operator bool())) {
if(previous.operator bool()) {
return std::coroutine_handle<void>(static_cast<std::coroutine_handle<void> &&>(previous));
} else {
return static_cast<std::coroutine_handle<void>>(std::noop_coroutine().operator std::coroutine_handle<void>());
return std::noop_coroutine().operator std::coroutine_handle<void>();
}

}
Expand Down
2 changes: 1 addition & 1 deletion tests/Issue536.expect
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ struct my_resumable

inline ~my_resumable() noexcept
{
if(static_cast<bool>(this->m_handle.operator bool())) {
if(this->m_handle.operator bool()) {
this->m_handle.destroy();
}

Expand Down
2 changes: 1 addition & 1 deletion tests/Issue536_2.expect
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ struct my_resumable

inline ~my_resumable() noexcept
{
if(static_cast<bool>(this->m_handle.operator bool())) {
if(this->m_handle.operator bool()) {
this->m_handle.destroy();
}

Expand Down
4 changes: 4 additions & 0 deletions tests/Issue593.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
struct A { operator int&(); };

int& ir = A();

11 changes: 11 additions & 0 deletions tests/Issue593.expect
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
struct A
{
operator int & ();

};



int & ir = A().operator int &();


2 changes: 1 addition & 1 deletion tests/Issue92.expect
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ struct generator<unsigned int>

inline ~generator() noexcept
{
if(static_cast<bool>(this->p.operator bool())) {
if(this->p.operator bool()) {
this->p.destroy();
}

Expand Down
2 changes: 1 addition & 1 deletion tests/LambdaHandler2Test.expect
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ int main()
};

using FuncPtr_8 = int (*)(int, char);
FuncPtr_8 fp = static_cast<int (*)(int, char)>(__lambda_8_26{}.operator __lambda_8_26::retType_8_26());
FuncPtr_8 fp = __lambda_8_26{}.operator __lambda_8_26::retType_8_26();
return 0;
}

Expand Down
6 changes: 3 additions & 3 deletions tests/LambdaHandlerCaptureLessTest.cerr
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
.tmp.cpp:35:5: error: templates cannot be declared inside of a local class
35 | template<class type_parameter_0_0, class type_parameter_0_1>
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.tmp.cpp:53:90: error: no type named 'retType_4_28' in '__lambda_4_28'
53 | FuncPtr_4 fp = static_cast<int (*)(int, char)>(__lambda_4_28{}.operator __lambda_4_28::retType_4_28());
| ~~~~~~~~~~~~~~~^
.tmp.cpp:53:58: error: no type named 'retType_4_28' in '__lambda_4_28'
53 | FuncPtr_4 fp = __lambda_4_28{}.operator __lambda_4_28::retType_4_28();
| ~~~~~~~~~~~~~~~^
3 errors generated.
2 changes: 1 addition & 1 deletion tests/LambdaHandlerCaptureLessTest.expect
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ int main()
};

using FuncPtr_4 = int (*)(int, char);
FuncPtr_4 fp = static_cast<int (*)(int, char)>(__lambda_4_28{}.operator __lambda_4_28::retType_4_28());
FuncPtr_4 fp = __lambda_4_28{}.operator __lambda_4_28::retType_4_28();
return 0;
}

Expand Down
Loading

0 comments on commit 17b84a8

Please sign in to comment.