Re: static_assert problem

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux