public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* static_assert problem
@ 2012-03-18 20:34 Michał Walenciak
  2012-03-18 20:41 ` Marc Glisse
  0 siblings, 1 reply; 2+ messages in thread
From: Michał Walenciak @ 2012-03-18 20:34 UTC (permalink / raw)
  To: gcc-help

Hi all

here i have a simple example:

template <int a, int c>
void foo()
{
	if (a > 0)
	  static_assert(c != 0, "fdfd");
	  
}


void bar()
{  
	foo<0, 0>(); 
}


when i compile it like: g++ a.cpp -std=c++0x -c

i get:
a.cpp: In function ‘void foo() [with int a = 0, int c = 0]’:
a.cpp:13:12:   instantiated from here
a.cpp:6:4: error: static assertion failed: "fdfd"

is it right? 'a' variable is not > 0, so static_assert should not be checked 
(imho)

regards

-- 
Michał Walenciak
gmail.com kicer86
http://kicer.sileman.net.pl
gg: 3729519

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: static_assert problem
  2012-03-18 20:34 static_assert problem Michał Walenciak
@ 2012-03-18 20:41 ` Marc Glisse
  0 siblings, 0 replies; 2+ messages in thread
From: Marc Glisse @ 2012-03-18 20:41 UTC (permalink / raw)
  To: Michał Walenciak; +Cc: gcc-help

On Sun, 18 Mar 2012, Michał Walenciak wrote:

> Hi all
>
> here i have a simple example:
>
> template <int a, int c>
> void foo()
> {
> 	if (a > 0)
> 	  static_assert(c != 0, "fdfd");
>
> }
>
>
> void bar()
> {
> 	foo<0, 0>();
> }
>
>
> when i compile it like: g++ a.cpp -std=c++0x -c
>
> i get:
> a.cpp: In function ‘void foo() [with int a = 0, int c = 0]’:
> a.cpp:13:12:   instantiated from here
> a.cpp:6:4: error: static assertion failed: "fdfd"
>
> is it right? 'a' variable is not > 0, so static_assert should not be checked
> (imho)

Yes it should. It is a static assertion, whereas "if" is a pure runtime 
object. There are some people trying to introduce a static version of 
"if", but that's not in C++11.

-- 
Marc Glisse

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2012-03-18 20:41 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-03-18 20:34 static_assert problem Michał Walenciak
2012-03-18 20:41 ` Marc Glisse

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).