https://github.com/vinayakdsci created
https://github.com/llvm/llvm-project/pull/83152
Fixes #82512
Adds diagnostics for lambda expressions being cast to boolean values, which
results in the expression always evaluating to true.
Earlier, Clang allowed compilation of such erroneous programs, b
llvmbot wrote:
@llvm/pr-subscribers-clang
Author: Vinayak Dev (vinayakdsci)
Changes
Fixes #82512
Adds diagnostics for lambda expressions being cast to boolean values, which
results in the expression always evaluating to true.
Earlier, Clang allowed compilation of such erroneous programs
https://github.com/AaronBallman edited
https://github.com/llvm/llvm-project/pull/83152
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
https://github.com/AaronBallman requested changes to this pull request.
Thank you for the fix!
There are some related test failures caught by precommit CI that need to be
addressed.
The issue in dr18xx.cpp looks to be a case where we should replace `bool b = `
with `auto b = ` (it doesn't cha
@@ -16538,6 +16538,27 @@ void Sema::DiagnoseAlwaysNonNullPointer(Expr *E,
}
}
+ // Complain if we are converting a lambda expression to a boolean value
+ if (auto *MCallExpr = dyn_cast(E)) {
+if (MCallExpr->getObjectType()->isRecordType()) {
+ if (auto *MRecor
@@ -16538,6 +16538,27 @@ void Sema::DiagnoseAlwaysNonNullPointer(Expr *E,
}
}
+ // Complain if we are converting a lambda expression to a boolean value
+ if (auto *MCallExpr = dyn_cast(E)) {
+if (MCallExpr->getObjectType()->isRecordType()) {
+ if (auto *MRecor
@@ -16538,6 +16538,27 @@ void Sema::DiagnoseAlwaysNonNullPointer(Expr *E,
}
}
+ // Complain if we are converting a lambda expression to a boolean value
+ if (auto *MCallExpr = dyn_cast(E)) {
+if (MCallExpr->getObjectType()->isRecordType()) {
+ if (auto *MRecor
vinayakdsci wrote:
> There are some related test failures caught by precommit CI that need to be
> addressed.
>
> The issue in dr18xx.cpp looks to be a case where we should replace `bool b =
> ` with `auto b = ` (it doesn't change the testing for what's discussed in
> http://wg21.link/cwg1837
@@ -16538,6 +16538,27 @@ void Sema::DiagnoseAlwaysNonNullPointer(Expr *E,
}
}
+ // Complain if we are converting a lambda expression to a boolean value
+ if (auto *MCallExpr = dyn_cast(E)) {
+if (MCallExpr->getObjectType()->isRecordType()) {
+ if (auto *MRecor
@@ -16538,6 +16538,27 @@ void Sema::DiagnoseAlwaysNonNullPointer(Expr *E,
}
}
+ // Complain if we are converting a lambda expression to a boolean value
+ if (auto *MCallExpr = dyn_cast(E)) {
+if (MCallExpr->getObjectType()->isRecordType()) {
+ if (auto *MRecor
AaronBallman wrote:
> > There are some related test failures caught by precommit CI that need to be
> > addressed.
> > The issue in dr18xx.cpp looks to be a case where we should replace `bool b
> > = ` with `auto b = ` (it doesn't change the testing for what's discussed in
> > http://wg21.link
https://github.com/vinayakdsci updated
https://github.com/llvm/llvm-project/pull/83152
>From 0e9d7e7ed96feb8c32be33ca9b1262bba32ab8b4 Mon Sep 17 00:00:00 2001
From: Vinayak Dev
Date: Tue, 27 Feb 2024 18:05:29 +0530
Subject: [PATCH] [Clang][Sema]: Diagnose lambda to bool implicit casts
---
cla
https://github.com/vinayakdsci updated
https://github.com/llvm/llvm-project/pull/83152
>From c65c6a379db75eb4bf38578106ba2aa4e894e3d8 Mon Sep 17 00:00:00 2001
From: Vinayak Dev
Date: Tue, 27 Feb 2024 18:05:29 +0530
Subject: [PATCH] [Clang][Sema]: Diagnose lambda to bool implicit casts
---
cla
https://github.com/Endilll edited
https://github.com/llvm/llvm-project/pull/83152
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
@@ -287,6 +287,11 @@ namespace dr1837 { // dr1837: 3.3
};
};
};
+ /* since-cxx11-warning@-6{{address of function '[] {
Endilll wrote:
Can you convert this to use a marker? We don't want readers to count relative
offsets. In other words, it should
https://github.com/Endilll requested changes to this pull request.
https://github.com/llvm/llvm-project/pull/83152
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
@@ -16538,6 +16538,24 @@ void Sema::DiagnoseAlwaysNonNullPointer(Expr *E,
}
}
+ // Complain if we are converting a lambda expression to a boolean value
+ if (const auto *MCallExpr = dyn_cast(E)) {
+if (MCallExpr->getObjectType()->isRecordType()) {
+ if (const
@@ -16538,6 +16538,24 @@ void Sema::DiagnoseAlwaysNonNullPointer(Expr *E,
}
}
+ // Complain if we are converting a lambda expression to a boolean value
+ if (const auto *MCallExpr = dyn_cast(E)) {
+if (MCallExpr->getObjectType()->isRecordType()) {
+ if (const
@@ -16538,6 +16538,24 @@ void Sema::DiagnoseAlwaysNonNullPointer(Expr *E,
}
}
+ // Complain if we are converting a lambda expression to a boolean value
+ if (const auto *MCallExpr = dyn_cast(E)) {
+if (MCallExpr->getObjectType()->isRecordType()) {
+ if (const
@@ -16538,6 +16538,24 @@ void Sema::DiagnoseAlwaysNonNullPointer(Expr *E,
}
}
+ // Complain if we are converting a lambda expression to a boolean value
+ if (const auto *MCallExpr = dyn_cast(E)) {
+if (MCallExpr->getObjectType()->isRecordType()) {
+ if (const
https://github.com/vinayakdsci updated
https://github.com/llvm/llvm-project/pull/83152
>From 613e7c0698f16292bb408be832c7ab3647f17195 Mon Sep 17 00:00:00 2001
From: Vinayak Dev
Date: Tue, 27 Feb 2024 18:05:29 +0530
Subject: [PATCH] [Clang][Sema]: Diagnose lambda to bool implicit casts
---
cla
vinayakdsci wrote:
Done! I added the diagnostic to the TableGen file, and passed in only the
Record's source range instead of the whole expression's. Now only the lambda's
initializer is highlighted in the diagnostic. I hope this does it!
https://github.com/llvm/llvm-project/pull/83152
___
@@ -16538,6 +16538,21 @@ void Sema::DiagnoseAlwaysNonNullPointer(Expr *E,
}
}
+ // Complain if we are converting a lambda expression to a boolean value
+ if (const auto *MCallExpr = dyn_cast(E)) {
+if (const auto *MRecordDecl = MCallExpr->getRecordDecl();
+
@@ -4127,8 +4127,8 @@ def ext_ms_impcast_fn_obj : ExtWarn<
"Microsoft extension">, InGroup;
def warn_impcast_pointer_to_bool : Warning<
-"address of%select{| function| array}0 '%1' will always evaluate to "
-"'true'">,
+"address of%select{| function| array| lambd
@@ -16538,6 +16538,21 @@ void Sema::DiagnoseAlwaysNonNullPointer(Expr *E,
}
}
+ // Complain if we are converting a lambda expression to a boolean value
+ if (const auto *MCallExpr = dyn_cast(E)) {
+if (const auto *MRecordDecl = MCallExpr->getRecordDecl();
+
https://github.com/vinayakdsci deleted
https://github.com/llvm/llvm-project/pull/83152
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
https://github.com/vinayakdsci updated
https://github.com/llvm/llvm-project/pull/83152
>From 640cbf94879217526e27884beefcbffa404fc082 Mon Sep 17 00:00:00 2001
From: Vinayak Dev
Date: Tue, 27 Feb 2024 18:05:29 +0530
Subject: [PATCH] [Clang][Sema]: Diagnose lambda to bool implicit casts
---
cla
vinayakdsci wrote:
@AaronBallman sorry for repeating the same mistake twice, I was unable to
correctly interpret what you wanted to say when you meant removing the lambda
body from the diagnostic.
I have made all the suggested changes and updated the tests. I hope I don't
come across as dumb :
AaronBallman wrote:
> @AaronBallman sorry for repeating the same mistake twice, I was unable to
> correctly interpret what you wanted to say when you meant removing the lambda
> body from the diagnostic. I have made all the suggested changes and updated
> the tests. I hope I don't come across
https://github.com/AaronBallman approved this pull request.
LGTM! @Endilll, do you have any concerns?
https://github.com/llvm/llvm-project/pull/83152
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinf
https://github.com/Endilll edited
https://github.com/llvm/llvm-project/pull/83152
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
@@ -281,7 +281,7 @@ namespace dr1837 { // dr1837: 3.3
struct A {
int f();
-bool b = [] {
+bool b = [] { // since-cxx11-warning{{address of lambda function pointer
conversion operator will always evaluate to 'true'}}
Endilll wrote:
Convert this
https://github.com/Endilll approved this pull request.
DR test changes look good, save for a nit.
https://github.com/llvm/llvm-project/pull/83152
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cf
https://github.com/shafik commented:
Thank you for this fix. I am happy the changes were not too different from my
suggestion. Sometimes problems end up being more difficult then they seem
initially.
https://github.com/llvm/llvm-project/pull/83152
__
@@ -16538,6 +16538,17 @@ void Sema::DiagnoseAlwaysNonNullPointer(Expr *E,
}
}
+ // Complain if we are converting a lambda expression to a boolean value
+ if (const auto *MCallExpr = dyn_cast(E)) {
+if (const auto *MRecordDecl = MCallExpr->getRecordDecl();
+
@@ -16538,6 +16538,17 @@ void Sema::DiagnoseAlwaysNonNullPointer(Expr *E,
}
}
+ // Complain if we are converting a lambda expression to a boolean value
+ if (const auto *MCallExpr = dyn_cast(E)) {
+if (const auto *MRecordDecl = MCallExpr->getRecordDecl();
+
https://github.com/shafik edited https://github.com/llvm/llvm-project/pull/83152
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
https://github.com/vinayakdsci updated
https://github.com/llvm/llvm-project/pull/83152
>From 60620d14509b4d097a56d0b61177dfe9c5a72b63 Mon Sep 17 00:00:00 2001
From: Vinayak Dev
Date: Tue, 27 Feb 2024 18:05:29 +0530
Subject: [PATCH] [Clang][Sema]: Diagnose lambda to bool implicit casts
---
cla
github-actions[bot] wrote:
:warning: C/C++ code formatter, clang-format found issues in your code.
:warning:
You can test this locally with the following command:
``bash
git-clang-format --diff 14d8c4563e045fc3da82cb7268b1066cfd1bb6f0
60620d14509b4d097a56d0b61177dfe9c5a72b63 --
https://github.com/vinayakdsci updated
https://github.com/llvm/llvm-project/pull/83152
>From 3d6100ae6fa291db24f26e2ccbce88293810e168 Mon Sep 17 00:00:00 2001
From: Vinayak Dev
Date: Tue, 27 Feb 2024 18:05:29 +0530
Subject: [PATCH] [Clang][Sema]: Diagnose lambda to bool implicit casts
---
cla
vinayakdsci wrote:
@shafik I have made the change in the code as you suggested. If everything
seems alright, could you land this for me?
Thanks a lot!
https://github.com/llvm/llvm-project/pull/83152
___
cfe-commits mailing list
cfe-commits@lists.llvm
https://github.com/AaronBallman closed
https://github.com/llvm/llvm-project/pull/83152
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
MaskRay wrote:
Created #83497 as a follow-up to suppress the diagnostic for certain template
instantiation uses.
I made one change to unblock our internal users
```
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wpointer-bool-conversion"
#endif
// functor_
43 matches
Mail list logo