summaryrefslogtreecommitdiffstats
path: root/clang/docs
diff options
context:
space:
mode:
Diffstat (limited to 'clang/docs')
-rw-r--r--clang/docs/LanguageExtensions.rst55
1 files changed, 55 insertions, 0 deletions
diff --git a/clang/docs/LanguageExtensions.rst b/clang/docs/LanguageExtensions.rst
index 7772bf53e8e..9871c23d9b4 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -2300,6 +2300,61 @@ automatically will insert one if the first argument to `llvm.coro.suspend` is
token `none`. If a user calls `__builin_suspend`, clang will insert `token none`
as the first argument to the intrinsic.
+Source location builtins
+------------------------
+
+Clang provides experimental builtins to support C++ standard library implementation
+of ``std::experimental::source_location`` as specified in http://wg21.link/N4600.
+With the exception of ``__builtin_COLUMN``, these builtins are also implemented by
+GCC.
+
+**Syntax**:
+
+.. code-block:: c
+
+ const char *__builtin_FILE();
+ const char *__builtin_FUNCTION();
+ unsigned __builtin_LINE();
+ unsigned __builtin_COLUMN(); // Clang only
+
+**Example of use**:
+
+.. code-block:: c++
+
+ void my_assert(bool pred, int line = __builtin_LINE(), // Captures line of caller
+ const char* file = __builtin_FILE(),
+ const char* function = __builtin_FUNCTION()) {
+ if (pred) return;
+ printf("%s:%d assertion failed in function %s\n", file, line, function);
+ std::abort();
+ }
+
+ struct MyAggregateType {
+ int x;
+ int line = __builtin_LINE(); // captures line where aggregate initialization occurs
+ };
+ static_assert(MyAggregateType{42}.line == __LINE__);
+
+ struct MyClassType {
+ int line = __builtin_LINE(); // captures line of the constructor used during initialization
+ constexpr MyClassType(int) { assert(line == __LINE__); }
+ };
+
+**Description**:
+
+The builtins ``__builtin_LINE``, ``__builtin_FUNCTION``, and ``__builtin_FILE`` return
+the values, at the "invocation point", for ``__LINE__``, ``__FUNCTION__``, and
+``__FILE__`` respectively. These builtins are constant expressions.
+
+When the builtins appear as part of a default function argument the invocation
+point is the location of the caller. When the builtins appear as part of a
+default member initializer, the invocation point is the location of the
+constructor or aggregate initialization used to create the object. Otherwise
+the invocation point is the same as the location of the builtin.
+
+When the invocation point of ``__builtin_FUNCTION`` is not a function scope the
+empty string is returned.
+
Non-standard C++11 Attributes
=============================
OpenPOWER on IntegriCloud