1b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// Copyright 2014 the V8 project authors. All rights reserved.
2b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// Use of this source code is governed by a BSD-style license that can be
3b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// found in the LICENSE file.
4b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
5b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch#ifndef V8_BASE_COMPILER_SPECIFIC_H_
6b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch#define V8_BASE_COMPILER_SPECIFIC_H_
7b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
8b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch#include "include/v8config.h"
9b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
10958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier// Annotate a typedef or function indicating it's ok if it's not used.
11b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// Use like:
12958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier//   typedef Foo Bar ALLOW_UNUSED_TYPE;
13b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch#if V8_HAS_ATTRIBUTE_UNUSED
14958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier#define ALLOW_UNUSED_TYPE __attribute__((unused))
15b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch#else
16958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier#define ALLOW_UNUSED_TYPE
17b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch#endif
18b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
19b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
20b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// Annotate a function indicating the caller must examine the return value.
21b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// Use like:
22b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch//   int foo() WARN_UNUSED_RESULT;
23b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch#if V8_HAS_ATTRIBUTE_WARN_UNUSED_RESULT
24b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch#define WARN_UNUSED_RESULT __attribute__((warn_unused_result))
25b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch#else
26b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch#define WARN_UNUSED_RESULT /* NOT SUPPORTED */
27b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch#endif
28b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
29537ba893e2530051ec7f296e769fdd37bb4ae4a0Ben Murdoch// Tell the compiler a function is using a printf-style format string.
30537ba893e2530051ec7f296e769fdd37bb4ae4a0Ben Murdoch// |format_param| is the one-based index of the format string parameter;
31537ba893e2530051ec7f296e769fdd37bb4ae4a0Ben Murdoch// |dots_param| is the one-based index of the "..." parameter.
32537ba893e2530051ec7f296e769fdd37bb4ae4a0Ben Murdoch// For v*printf functions (which take a va_list), pass 0 for dots_param.
33537ba893e2530051ec7f296e769fdd37bb4ae4a0Ben Murdoch// (This is undocumented but matches what the system C headers do.)
34537ba893e2530051ec7f296e769fdd37bb4ae4a0Ben Murdoch#if defined(__GNUC__)
35537ba893e2530051ec7f296e769fdd37bb4ae4a0Ben Murdoch#define PRINTF_FORMAT(format_param, dots_param) \
36537ba893e2530051ec7f296e769fdd37bb4ae4a0Ben Murdoch  __attribute__((format(printf, format_param, dots_param)))
37537ba893e2530051ec7f296e769fdd37bb4ae4a0Ben Murdoch#else
38537ba893e2530051ec7f296e769fdd37bb4ae4a0Ben Murdoch#define PRINTF_FORMAT(format_param, dots_param)
39537ba893e2530051ec7f296e769fdd37bb4ae4a0Ben Murdoch#endif
40014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch
41014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch// The C++ standard requires that static const members have an out-of-class
42014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch// definition (in a single compilation unit), but MSVC chokes on this (when
43014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch// language extensions, which are required, are enabled). (You're only likely to
44014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch// notice the need for a definition if you take the address of the member or,
45014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch// more commonly, pass it to a function that takes it as a reference argument --
46014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch// probably an STL function.) This macro makes MSVC do the right thing. See
47014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch// http://msdn.microsoft.com/en-us/library/34h23df8(v=vs.100).aspx for more
48014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch// information. Use like:
49014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch//
50014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch// In .h file:
51014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch//   struct Foo {
52014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch//     static const int kBar = 5;
53014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch//   };
54014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch//
55014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch// In .cc file:
56014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch//   STATIC_CONST_MEMBER_DEFINITION const int Foo::kBar;
57014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch#if V8_HAS_DECLSPEC_SELECTANY
58014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch#define STATIC_CONST_MEMBER_DEFINITION __declspec(selectany)
59014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch#else
60014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch#define STATIC_CONST_MEMBER_DEFINITION
61014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch#endif
62014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch
63b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch#endif  // V8_BASE_COMPILER_SPECIFIC_H_
64