Bug 113308 - Support C++11 static_assert
Summary: Support C++11 static_assert
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Web Template Framework (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Allan Sandfeld Jensen
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-03-26 07:20 PDT by Allan Sandfeld Jensen
Modified: 2013-03-27 10:31 PDT (History)
7 users (show)

See Also:


Attachments
Patch (1.97 KB, patch)
2013-03-26 07:24 PDT, Allan Sandfeld Jensen
no flags Details | Formatted Diff | Diff
Patch (3.83 KB, patch)
2013-03-27 03:55 PDT, Allan Sandfeld Jensen
no flags Details | Formatted Diff | Diff
Patch (2.98 KB, patch)
2013-03-27 03:57 PDT, Allan Sandfeld Jensen
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Allan Sandfeld Jensen 2013-03-26 07:20:28 PDT
When available we use the Clang extension _Static_assert for compile assertion since this is just a C version of the C++11 static assert we should use the C++11 version when possible.

Note this is not always possible since Assertions.h where COMPILE_ASSERT is defined can be used from both C and C++, and COMPILE_ASSERT will therefore still not be available in C for non clang compilers.
Comment 1 Allan Sandfeld Jensen 2013-03-26 07:24:03 PDT
Created attachment 195083 [details]
Patch
Comment 2 Alexey Proskuryakov 2013-03-26 11:01:43 PDT
Comment on attachment 195083 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=195083&action=review

> Source/WTF/wtf/Assertions.h:348
>  #if COMPILER_SUPPORTS(C_STATIC_ASSERT)
>  #define COMPILE_ASSERT(exp, name) _Static_assert((exp), #name)

I think that this should have a comment explaining why we still have this:

// Unlike static_assert below, this also works in plain C code.

That said, I'm unsure if we ever use - or want to use - COMPILE_ASSERT in plain C code.

> Source/WTF/wtf/Compiler.h:128
> +#define WTF_COMPILER_SUPPORTS_CXX_STATIC_ASSERT 1

Shouldn't this be defined for clang too? The behavior in this patch would not be affected, but it's better to not leave such a tripmine for later IMO.
Comment 3 Allan Sandfeld Jensen 2013-03-27 03:55:01 PDT
Created attachment 195266 [details]
Patch

Added detection of C++11 static_assert to clang, and C11 _Static_assert to GCC.
Comment 4 Allan Sandfeld Jensen 2013-03-27 03:57:06 PDT
Created attachment 195267 [details]
Patch

Remove accidentially uploaded change.
Comment 5 Allan Sandfeld Jensen 2013-03-27 10:31:03 PDT
Comment on attachment 195267 [details]
Patch

Clearing flags on attachment: 195267

Committed r146993: <http://trac.webkit.org/changeset/146993>
Comment 6 Allan Sandfeld Jensen 2013-03-27 10:31:07 PDT
All reviewed patches have been landed.  Closing bug.