blob: ffd5a44e141d069fd8f11996ce15da2c41d02b6c [file] [log] [blame]
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001// Copyright 2014 the V8 project authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef V8_BASE_COMPILER_SPECIFIC_H_
6#define V8_BASE_COMPILER_SPECIFIC_H_
7
8#include "include/v8config.h"
9
Emily Bernierd0a1eb72015-03-24 16:35:39 -040010// Annotate a typedef or function indicating it's ok if it's not used.
Ben Murdochb8a8cc12014-11-26 15:28:44 +000011// Use like:
Emily Bernierd0a1eb72015-03-24 16:35:39 -040012// typedef Foo Bar ALLOW_UNUSED_TYPE;
Ben Murdochb8a8cc12014-11-26 15:28:44 +000013#if V8_HAS_ATTRIBUTE_UNUSED
Emily Bernierd0a1eb72015-03-24 16:35:39 -040014#define ALLOW_UNUSED_TYPE __attribute__((unused))
Ben Murdochb8a8cc12014-11-26 15:28:44 +000015#else
Emily Bernierd0a1eb72015-03-24 16:35:39 -040016#define ALLOW_UNUSED_TYPE
Ben Murdochb8a8cc12014-11-26 15:28:44 +000017#endif
18
19
Ben Murdochb8a8cc12014-11-26 15:28:44 +000020// Annotate a function indicating the caller must examine the return value.
21// Use like:
22// int foo() WARN_UNUSED_RESULT;
23#if V8_HAS_ATTRIBUTE_WARN_UNUSED_RESULT
24#define WARN_UNUSED_RESULT __attribute__((warn_unused_result))
25#else
26#define WARN_UNUSED_RESULT /* NOT SUPPORTED */
27#endif
28
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000029
30// The C++ standard requires that static const members have an out-of-class
31// definition (in a single compilation unit), but MSVC chokes on this (when
32// language extensions, which are required, are enabled). (You're only likely to
33// notice the need for a definition if you take the address of the member or,
34// more commonly, pass it to a function that takes it as a reference argument --
35// probably an STL function.) This macro makes MSVC do the right thing. See
36// http://msdn.microsoft.com/en-us/library/34h23df8(v=vs.100).aspx for more
37// information. Use like:
38//
39// In .h file:
40// struct Foo {
41// static const int kBar = 5;
42// };
43//
44// In .cc file:
45// STATIC_CONST_MEMBER_DEFINITION const int Foo::kBar;
46#if V8_HAS_DECLSPEC_SELECTANY
47#define STATIC_CONST_MEMBER_DEFINITION __declspec(selectany)
48#else
49#define STATIC_CONST_MEMBER_DEFINITION
50#endif
51
Ben Murdochb8a8cc12014-11-26 15:28:44 +000052#endif // V8_BASE_COMPILER_SPECIFIC_H_