Boost_static_assert Error Message
Contents |
Maddock Steve Cleary Copyright © 2000, 2005 Steve Cleary boost_static_assert msg and John Maddock Distributed under the Boost Software License, boost_static_assert invalid application of sizeof Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt ) Table of Contents assert error message java Overview and Tutorial Use at namespace scope. Use at function scope Use at class scope Use in templates How it works Test assert error message python Programs This manual is also available in printer friendly PDF format. Overview and Tutorial Use at namespace scope. Use at function scope Use at class scope Use in templates The header <boost/static_assert.hpp> supplies two macros: BOOST_STATIC_ASSERT(x) BOOST_STATIC_ASSERT_MSG(x, msg) Both generate
Static_assert C++11
a compile time error message if the integral-constant-expression x is not true. In other words, they are the compile time equivalent of the assert macro; this is sometimes known as a "compile-time-assertion", but will be called a "static assertion" throughout these docs. Note that if the condition is true, then the macros will generate neither code nor data - and the macros can also be used at either namespace, class or function scope. When used in a template, the static assertion will be evaluated at the time the template is instantiated; this is particularly useful for validating template parameters. If the C++0x static_assert feature is available, both macros will use it. For BOOST_STATIC_ASSERT(x), the error message will be a stringized version of x. For BOOST_STATIC_ASSERT_MSG(x, Static_assert Gcc Discuss the workings and policies of this site About Us Learn boost_static_assert example more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us boost_static_assert implementation Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like http://www.boost.org/doc/libs/1_61_0/doc/html/boost_staticassert.html you, helping each other. Join them; it only takes a minute: Sign up boost static_assert with message? up vote 3 down vote favorite on 1.43 boost it seems that BOOST_STATIC_ASSERT just allows to put a boolean value, is there some alternative that allows me to display a message as well on the compile error? c++ debugging boost http://stackoverflow.com/questions/3241749/boost-static-assert-with-message metaprogramming static-assert share|improve this question asked Jul 13 '10 at 21:36 lurscher 7,8341166133 add a comment| 3 Answers 3 active oldest votes up vote 5 down vote accepted MPL has BOOST_MPL_ASSERT_MSG. E.g. using GCC 4.2. with this: BOOST_MPL_ASSERT_MSG(false, THIS_DOESNT_WORK, (void)); ... results in: /path/to/file.cpp:42: error: no matching function for call to 'assertion_failed(mpl_::failed************ (function()::THIS_DOESNT_WORK::************)())' share|improve this answer edited Jul 13 '10 at 21:46 answered Jul 13 '10 at 21:39 Georg Fritzsche 71.9k16150210 add a comment| up vote 3 down vote Have you tried something like: BOOST_STATIC_ASSERT(sizeof(long) == 64 && "Must have 64-bit long!") If your compiler supports the C++0x static_assert, you can do: static_assert(sizeof(long) == 64, "Must have 64-bit long!") share|improve this answer answered Jul 13 '10 at 21:42 reece 4,46911318 i tried this but i got this error: error: invalid application of ‘sizeof’ to incomplete type ‘boost::STATIC_ASSERTION_FAILURE generates a compile time error message if the integral-constant-expression x is not true. In other words it is the compile time equivalent of http://www.cs.fsu.edu/~lacher/boost_1_32_0/libs/static_assert/static_assert.htm the assert macro; this is sometimes known as a "compile-time-assertion", but https://groups.google.com/d/topic/boost-list/r1i5QUhi6I0 will be called a "static assertion" throughout these docs. Note that if the condition is true, then the macro will generate neither code nor data - and the macro can also be used at either namespace, class or function scope. When used in a error message template, the static assertion will be evaluated at the time the template is instantiated; this is particularly useful for validating template parameters. One of the aims of BOOST_STATIC_ASSERT is to generate readable error messages. These immediately tell the user that a library is being used in a manner that is not supported. While error messages obviously assert error message differ from compiler to compiler, but you should see something like: Illegal use of STATIC_ASSERTION_FAILURE from GoogleSign inHidden fieldsSearch for groups or messages