10 Commits

Author SHA1 Message Date
Anutosh Bhat
419d1c2adb
Revert "[clang-repl] Ensure clang-repl accepts all C keywords supported in all language models (#142749) (#142933)
This broke CI on platforms such as PPC64LE and AIX due to _Float16 not being supported.
We will reintroduce the changes later with proper platform guards and tests.

This reverts commit 7ca7bcb7d8dcf26fc0281697fe47aa6cdb3884c0.
2025-06-05 13:55:06 +03:00
Anutosh Bhat
7ca7bcb7d8
[clang-repl] Ensure clang-repl accepts all C keywords supported in all language models (#142749)
As can be seen through the docs
(7e1fa09ce2/clang/docs/LanguageExtensions.rst (c-keywords-supported-in-all-language-modes)),
Clang supports certain C keywords in all language modes — this patch
ensures clang-repl handles them consistently.

Here's an example testing all the above keywords. We have everything in
place except `_Imaginary` (_Complex works but _Imaginary doesn't which
was weird) and `_Noreturn`
2025-06-05 11:23:50 +05:30
kelbon
818de32f31
Warning for incorrect use of 'pure' attribute (#78200)
This adds a warning when applying the `pure` attribute along with the `const` attribute, or when applying the `pure` attribute to a function with a `void` return type (including constructors and destructors).

Fixes https://github.com/llvm/llvm-project/issues/77482
2024-01-20 12:37:35 -05:00
Jonas Hahnfeld
6c274ba410 [clang-repl] Disambiguate declarations with private typedefs
Member functions and static variable definitions may use typedefs that
are private in the global context, but fine in the class context.

Differential Revision: https://reviews.llvm.org/D157838
2023-08-23 11:29:26 +02:00
Jonas Hahnfeld
ba475a4a34 [clang-repl] Disambiguate global namespace identifiers
A double colon starts an identifier name in the global namespace and
must be tentatively parsed as such.

Differential Revision: https://reviews.llvm.org/D157480
2023-08-14 10:11:27 +02:00
Jonas Hahnfeld
da555f750a [clang-repl] Additional test for disambiguation of templates
This test case was fixed in commit 2c4620c1 ("Consider the scope spec
in template lookups for deduction guides."), but it is worth having a
dedicated test case with a templated struct and a using declaration.

Differential Revision: https://reviews.llvm.org/D157477
2023-08-09 16:15:14 +02:00
Vassil Vassilev
2c4620c1da [clang-repl] Consider the scope spec in template lookups for deduction guides.
isDeductionGuideName looks up the underlying template and if the template name
is qualified we miss that qualification resulting in an error. This issue
resurfaced in clang-repl where we call isDeductionGuideName more often to
distinguish between if we had a statement or declaration.

This patch passes the CXXScopeSpec information down to LookupTemplateName to
make the lookup more precise.

Differential revision: https://reviews.llvm.org/D147319
2023-05-08 17:54:56 +00:00
Vassil Vassilev
87ae746924 [clang-repl] Add a test coverage for nested out-of-line dtor disambiguation.
This came up as a review comment in https://reviews.llvm.org/D148425
2023-05-02 09:39:48 +00:00
Vassil Vassilev
5a9abe8466 [clang-repl] Correctly disambiguate dtor declarations from statements.
Differential revision: https://reviews.llvm.org/D148425
2023-04-30 19:44:52 +00:00
Vassil Vassilev
dc4889357a [clang-repl] Support statements on global scope in incremental mode.
This patch teaches clang to parse statements on the global scope to allow:
```
./bin/clang-repl
clang-repl> int i = 12;
clang-repl> ++i;
clang-repl> extern "C" int printf(const char*,...);
clang-repl> printf("%d\n", i);
13
clang-repl> %quit
```

Generally, disambiguating between statements and declarations is a non-trivial
task for a C++ parser. The challenge is to allow both standard C++ to be
translated as if this patch does not exist and in the cases where the user typed
a statement to be executed as if it were in a function body.

Clang's Parser does pretty well in disambiguating between declarations and
expressions. We have added DisambiguatingWithExpression flag which allows us to
preserve the existing and optimized behavior where needed and implement the
extra rules for disambiguating. Only few cases require additional attention:
  * Constructors/destructors -- Parser::isConstructorDeclarator was used in to
    disambiguate between ctor-looking declarations and statements on the global
    scope(eg. `Ns::f()`).
  * The template keyword -- the template keyword can appear in both declarations
    and statements. This patch considers the template keyword to be a declaration
    starter which breaks a few cases in incremental mode which will be tackled
    later.
  * The inline (and similar) keyword -- looking at the first token in many cases
    allows us to classify what is a declaration.
  * Other language keywords and specifiers -- ObjC/ObjC++/OpenCL/OpenMP rely on
    pragmas or special tokens which will be handled in subsequent patches.

The patch conceptually models a "top-level" statement into a TopLevelStmtDecl.
The TopLevelStmtDecl is lowered into a void function with no arguments.
We attach this function to the global initializer list to execute the statement
blocks in the correct order.

Differential revision: https://reviews.llvm.org/D127284
2022-12-03 07:18:07 +00:00