* [PATCH] Adding warning for constexpr's
@ 2015-06-12 21:35 Andres Tiraboschi
2015-06-13 2:33 ` Joseph Myers
0 siblings, 1 reply; 5+ messages in thread
From: Andres Tiraboschi @ 2015-06-12 21:35 UTC (permalink / raw)
To: gcc-patches
Hi, this patch is for adding a warning when a constexpr cannot be evaluated at compile time.
This is a single case:
type var = fun(args...), with fun declared as a constexpr.
diff --git a/gcc/common.opt b/gcc/common.opt
index b49ac46..88374b1 100644
--- a/gcc/common.opt
+++ b/gcc/common.opt
@@ -581,6 +581,10 @@ Winline
Common Var(warn_inline) Warning
Warn when an inlined function cannot be inlined
+Wconstexpr
+Common Var(warn_constexpr) Warning
+Warn when a constexpr function is not evaluated at compile time
+
Winvalid-memory-model
Common Var(warn_invalid_memory_model) Init(1) Warning
Warn when an atomic memory model parameter is known to be outside the valid range.
diff --git a/gcc/cp/typeck2.c b/gcc/cp/typeck2.c
index 80a6939..e25c240 100644
--- a/gcc/cp/typeck2.c
+++ b/gcc/cp/typeck2.c
@@ -842,6 +842,15 @@ store_init_value (tree decl, tree init, vec<tree, va_gc>** cleanups, int flags)
DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl) = const_init;
TREE_CONSTANT (decl) = const_init && decl_maybe_constant_var_p (decl);
}
+ else if (TREE_CODE(init) == CALL_EXPR)
+ {
+ tree fn = TREE_OPERAND(CALL_EXPR_FN(init), 0);
+ if (DECL_DECLARED_CONSTEXPR_P(fn) && warn_constexpr)
+ {
+ warning (OPT_Wconstexpr, "function %q+F cannot be evaluated at compile time", fn);
+ warning (OPT_Wconstexpr, "called from here");
+ }
+ }
if (cxx_dialect >= cxx14)
/* Handle aggregate NSDMI in non-constant initializers, too. */
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] Adding warning for constexpr's
2015-06-12 21:35 [PATCH] Adding warning for constexpr's Andres Tiraboschi
@ 2015-06-13 2:33 ` Joseph Myers
2015-06-15 15:12 ` Andres Tiraboschi
2015-06-15 19:58 ` Andres Tiraboschi
0 siblings, 2 replies; 5+ messages in thread
From: Joseph Myers @ 2015-06-13 2:33 UTC (permalink / raw)
To: Andres Tiraboschi; +Cc: gcc-patches
On Fri, 12 Jun 2015, Andres Tiraboschi wrote:
> Hi, this patch is for adding a warning when a constexpr cannot be evaluated at compile time.
> This is a single case:
> type var = fun(args...), with fun declared as a constexpr.
All options need documenting in invoke.texi. All diagnostics need
testcases added to the testsuite. C++-specific options go in c.opt and
should be listed as C++ ObjC++, not Common. All new diagnostics should
use warning_at etc. with explicit locations passed, unless there is some
strong reason it's hard to get the relevant location when the warning is
given.
--
Joseph S. Myers
joseph@codesourcery.com
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] Adding warning for constexpr's
2015-06-13 2:33 ` Joseph Myers
@ 2015-06-15 15:12 ` Andres Tiraboschi
2015-06-15 19:58 ` Andres Tiraboschi
1 sibling, 0 replies; 5+ messages in thread
From: Andres Tiraboschi @ 2015-06-15 15:12 UTC (permalink / raw)
To: Joseph Myers, GCC Patches
Hi, thanks for your answer. I was trying with warning_at this way
instead that I was doing before:
+ else if (TREE_CODE(init) == CALL_EXPR)
+ {
+ tree fn = TREE_OPERAND(CALL_EXPR_FN(init), 0);
+ if (DECL_DECLARED_CONSTEXPR_P(fn) && warn_constexpr)
+ warning_at (DECL_SOURCE_LINE(decl), OPT_Wconstexpr,
"function %q+F cannot be evaluated at compile time", fn);
+
where "decl" is the declaration that is being initializated. For some
reason this isn't working. Checking with gdb I realised that
warning_at in this case is returnin false. I don't know if I am
missing something.
2015-06-12 18:35 GMT-03:00 Joseph Myers <joseph@codesourcery.com>:
> On Fri, 12 Jun 2015, Andres Tiraboschi wrote:
>
>> Hi, this patch is for adding a warning when a constexpr cannot be evaluated at compile time.
>> This is a single case:
>> type var = fun(args...), with fun declared as a constexpr.
>
> All options need documenting in invoke.texi. All diagnostics need
> testcases added to the testsuite. C++-specific options go in c.opt and
> should be listed as C++ ObjC++, not Common. All new diagnostics should
> use warning_at etc. with explicit locations passed, unless there is some
> strong reason it's hard to get the relevant location when the warning is
> given.
>
> --
> Joseph S. Myers
> joseph@codesourcery.com
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] Adding warning for constexpr's
2015-06-13 2:33 ` Joseph Myers
2015-06-15 15:12 ` Andres Tiraboschi
@ 2015-06-15 19:58 ` Andres Tiraboschi
2015-06-16 0:39 ` Mike Stump
1 sibling, 1 reply; 5+ messages in thread
From: Andres Tiraboschi @ 2015-06-15 19:58 UTC (permalink / raw)
To: Joseph Myers, GCC Patches
2015-06-12 18:35 GMT-03:00 Joseph Myers <joseph@codesourcery.com>:
> On Fri, 12 Jun 2015, Andres Tiraboschi wrote:
>
>> Hi, this patch is for adding a warning when a constexpr cannot be evaluated at compile time.
>> This is a single case:
>> type var = fun(args...), with fun declared as a constexpr.
>
> All options need documenting in invoke.texi. All diagnostics need
> testcases added to the testsuite. C++-specific options go in c.opt and
> should be listed as C++ ObjC++, not Common. All new diagnostics should
> use warning_at etc. with explicit locations passed, unless there is some
> strong reason it's hard to get the relevant location when the warning is
> given.
>
> --
> Joseph S. Myers
> joseph@codesourcery.com
Hi, do you know where is the .exp file for the tests in
.../gcc/testsuite/g++.dg/warn?
I can't find it. Thanks again
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] Adding warning for constexpr's
2015-06-15 19:58 ` Andres Tiraboschi
@ 2015-06-16 0:39 ` Mike Stump
0 siblings, 0 replies; 5+ messages in thread
From: Mike Stump @ 2015-06-16 0:39 UTC (permalink / raw)
To: Andres Tiraboschi; +Cc: Joseph Myers, GCC Patches
On Jun 15, 2015, at 12:55 PM, Andres Tiraboschi <andres.tiraboschi@tallertechnologies.com> wrote:
>
> Hi, do you know where is the .exp file for the tests in
> .../gcc/testsuite/g++.dg/warn?
> I can't find it.
find srcdir -name \*.exp -print will show you all of them. You’ll discover that a .exp file can run the entire tree under it. In this case, look in the parent directory.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2015-06-16 0:37 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-06-12 21:35 [PATCH] Adding warning for constexpr's Andres Tiraboschi
2015-06-13 2:33 ` Joseph Myers
2015-06-15 15:12 ` Andres Tiraboschi
2015-06-15 19:58 ` Andres Tiraboschi
2015-06-16 0:39 ` Mike Stump
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).