]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
runtime(c): Do not highlight noreturn in C++ code
authorWu Yongwei <wuyongwei@gmail.com>
Thu, 15 Jan 2026 20:37:14 +0000 (20:37 +0000)
committerChristian Brabandt <cb@256bit.org>
Thu, 15 Jan 2026 20:37:14 +0000 (20:37 +0000)
closes: #19170

Signed-off-by: Wu Yongwei <wuyongwei@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
runtime/syntax/c.vim
runtime/syntax/testdir/dumps/c_noreturn_00.dump [new file with mode: 0644]
runtime/syntax/testdir/dumps/cpp_noreturn_00.dump [new file with mode: 0644]
runtime/syntax/testdir/input/c_noreturn.c [new file with mode: 0644]
runtime/syntax/testdir/input/cpp_noreturn.cpp [new file with mode: 0644]

index d2f2b85b42f6e601122fbc6aa70b2c09a36bd05c..64bcd3e36878d85777e347a6dd5bce441b165059 100644 (file)
@@ -1,7 +1,7 @@
 " Vim syntax file
 " Language:            C
 " Maintainer:          The Vim Project <https://github.com/vim/vim>
-" Last Change:         2025 Nov 18
+" Last Change:         2026 Jan 13
 " Former Maintainer:   Bram Moolenaar <Bram@vim.org>
 
 " Quit when a (custom) syntax file was already loaded
@@ -326,7 +326,10 @@ if !exists("c_no_c11")
   syn keyword  cOperator       _Alignof alignof
   syn keyword  cStorageClass   _Atomic
   syn keyword  cOperator       _Generic
-  syn keyword  cStorageClass   _Noreturn noreturn
+  syn keyword  cStorageClass   _Noreturn
+  if !s:in_cpp_family
+    syn keyword        cStorageClass   noreturn
+  endif
   syn keyword  cOperator       _Static_assert static_assert
   syn keyword  cStorageClass   _Thread_local thread_local
   syn keyword   cType          char16_t char32_t
diff --git a/runtime/syntax/testdir/dumps/c_noreturn_00.dump b/runtime/syntax/testdir/dumps/c_noreturn_00.dump
new file mode 100644 (file)
index 0000000..7bb7380
--- /dev/null
@@ -0,0 +1,20 @@
+>#+0#e000e06#ffffff0|i|n|c|l|u|d|e| |<+0#e000002&|s|t|d|i|o|.|h|>| +0#0000000&@56
+|#+0#e000e06&|i|n|c|l|u|d|e| |<+0#e000002&|s|t|d|l|i|b|.|h|>| +0#0000000&@55
+|#+0#e000e06&|i|n|c|l|u|d|e| |<+0#e000002&|s|t|d|n|o|r|e|t|u|r|n|.|h|>| +0#0000000&@50
+@75
+|/+0#0000e05&@1| |c|a|u|s|e|s| |u|n|d|e|f|i|n|e|d| |b|e|h|a|v|i|o|r| |i|f| |i| |<|=| |0| +0#0000000&@36
+|/+0#0000e05&@1| |e|x|i|t|s| |i|f| |i| |>| |0| +0#0000000&@57
+|n+0#00e0003&|o|r|e|t|u|r|n| +0#0000000&|v+0#00e0003&|o|i|d| +0#0000000&|e|x|i|t|_|n|o|w|(|i+0#00e0003&|n|t| +0#0000000&|i|)| |/+0#0000e05&@1| |o|r| |_|N|o|r|e|t|u|r|n| |v|o|i|d| |e|x|i|t|_|n|o|w|(|i|n|t| |i|)| +0#0000000&@8
+|{| @73
+@4|i+0#af5f00255&|f| +0#0000000&|(|i| |>| |0+0#e000002&|)+0#0000000&| @60
+@8|e|x|i|t|(|i|)|;| @58
+|}| @73
+@75
+|i+0#00e0003&|n|t| +0#0000000&|m|a|i|n|(|v+0#00e0003&|o|i|d|)+0#0000000&| @60
+|{| @73
+@4|p|u|t|s|(|"+0#e000002&|P|r|e|p|a|r|i|n|g| |t|o| |e|x|i|t|.@2|"|)+0#0000000&|;| @41
+@4|e|x|i|t|_|n|o|w|(|2+0#e000002&|)+0#0000000&|;| @58
+@4|p|u|t|s|(|"+0#e000002&|T|h|i|s| |c|o|d|e| |i|s| |n|e|v|e|r| |e|x|e|c|u|t|e|d|.|"|)+0#0000000&|;| @33
+|}| @73
+|~+0#4040ff13&| @73
+| +0#0000000&@56|1|,|1| @10|A|l@1| 
diff --git a/runtime/syntax/testdir/dumps/cpp_noreturn_00.dump b/runtime/syntax/testdir/dumps/cpp_noreturn_00.dump
new file mode 100644 (file)
index 0000000..e2cfd25
--- /dev/null
@@ -0,0 +1,20 @@
+>#+0#e000e06#ffffff0|i|n|c|l|u|d|e| |<+0#e000002&|s|t|d|i|o|.|h|>| +0#0000000&@56
+|#+0#e000e06&|i|n|c|l|u|d|e| |<+0#e000002&|s|t|d|l|i|b|.|h|>| +0#0000000&@55
+@75
+|[@1|n|o|r|e|t|u|r|n|]@1| |v+0#00e0003&|o|i|d| +0#0000000&|e|r@1|o|r|_|e|x|i|t|(|c+0#00e0003&|o|n|s|t| +0#0000000&|c+0#00e0003&|h|a|r|*+0#0000000&| |r|e|a|s|o|n|)| @26
+|{| @73
+@4|p|r|i|n|t|f|(|"+0#e000002&|E|r@1|o|r|:| |%+0#e000e06&|s|\|n|"+0#e000002&|,+0#0000000&| |r|e|a|s|o|n|)|;| @40
+@4|e|x|i|t|(|1+0#e000002&|)+0#0000000&|;| @62
+|}| @73
+@75
+|i+0#00e0003&|n|t| +0#0000000&|m|a|i|n|(|v+0#00e0003&|o|i|d|)+0#0000000&| @60
+|{| @73
+@4|p|u|t|s|(|"+0#e000002&|P|r|e|p|a|r|i|n|g| |t|o| |e|x|i|t|.@2|"|)+0#0000000&|;| @41
+@4|e|r@1|o|r|_|e|x|i|t|(|"+0#e000002&|A|s@1|u|m|e| |s|o|m|e|t|h|i|n|g| |i|s| |w|r|o|n|g|"|)+0#0000000&|;| @30
+@4|p|u|t|s|(|"+0#e000002&|T|h|i|s| |c|o|d|e| |i|s| |n|e|v|e|r| |e|x|e|c|u|t|e|d|.|"|)+0#0000000&|;| @33
+|}| @73
+|~+0#4040ff13&| @73
+|~| @73
+|~| @73
+|~| @73
+| +0#0000000&@56|1|,|1| @10|A|l@1| 
diff --git a/runtime/syntax/testdir/input/c_noreturn.c b/runtime/syntax/testdir/input/c_noreturn.c
new file mode 100644 (file)
index 0000000..a2413c8
--- /dev/null
@@ -0,0 +1,18 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdnoreturn.h>
+
+// causes undefined behavior if i <= 0
+// exits if i > 0
+noreturn void exit_now(int i) // or _Noreturn void exit_now(int i)
+{
+    if (i > 0)
+        exit(i);
+}
+
+int main(void)
+{
+    puts("Preparing to exit...");
+    exit_now(2);
+    puts("This code is never executed.");
+}
diff --git a/runtime/syntax/testdir/input/cpp_noreturn.cpp b/runtime/syntax/testdir/input/cpp_noreturn.cpp
new file mode 100644 (file)
index 0000000..c2b729f
--- /dev/null
@@ -0,0 +1,15 @@
+#include <stdio.h>
+#include <stdlib.h>
+
+[[noreturn]] void error_exit(const char* reason)
+{
+    printf("Error: %s\n", reason);
+    exit(1);
+}
+
+int main(void)
+{
+    puts("Preparing to exit...");
+    error_exit("Assume something is wrong");
+    puts("This code is never executed.");
+}