royqh1979 / RedPanda-CPP

A light-weight C/C++ IDE based on Qt
GNU General Public License v3.0
953 stars 103 forks source link

如果在全局作用域中使用 static,extern,constexpr,consteval,constinit,预处理条件指令,那么后续的类型输入没有补全提示 #300

Closed West-Pavilion closed 6 months ago

West-Pavilion commented 6 months ago

如果在全局作用域中使用 static,extern,constexpr,consteval,constinit,预处理条件指令,那么后续的类型输入没有补全提示

如果在全局作用域(C++全局命名空间作用域)中使用 static,extern,constexpr,consteval,constinit,预处理条件指令,那么后续的类型输入没有补全提示。

请考虑如下 C++ 代码:

#include <iostream>

/* 如果在全局作用域中使用 static,extern,constexpr,consteval,
 * constinit,预处理条件指令,那么后续的类型输入没有补全提示.cpp */

/* 全局作用域中的 static 后的类型输入没有补全提示 */
static int static_var;
static void static_fun() {
    std::cout << "static_fun has been invoked" << std::endl;
}

/* 全局作用域中的 extern 后的类型输入没有补全提示 */
extern int extern_var;
extern void extern_fun();

/* 全局作用域中的 constexpr 后的类型输入没有补全提示 */
constexpr int constexpr_var = 8888;
constexpr void constexpr_fun(){
    static_var = 4560;
}

/* 全局作用域中的 预处理条件指令 #if 后的宏名没有补全提示 */
#if __cplusplus > 201703L
/* 全局作用域中的 constinit 后的类型输入没有补全提示 */
constinit int constinit_var = 1314;
consteval int consteval_fun(int i){
    if(i > 1000)
        return 4321;
    return 1234;
}
constinit auto consteval_res = consteval_fun(462);
#endif

int main(){
    static_fun();
    std::cout << "static_var: " << static_var << std::endl;
    constexpr_fun();
    std::cout << "static_var: " << static_var << std::endl;
    extern_fun();
    std::cout << "extern_var: " << extern_var << std::endl;
    /* 函数作用域中的 预处理条件指令 #if 后的宏名有补全提示 */
#if __cplusplus > 201703L
    std::cout << constinit_var << std::endl;
    constinit_var = consteval_fun(2024);
    std::cout << constinit_var << std::endl;
    std::cout << consteval_res << std::endl;
#endif
}

/* extern 函数的定义,这里没有 extern_fun 的补全提示 */
void extern_fun(){
    std::cout << "extern_fun has been invoked" << std::endl;
}

/* extern 变量的定义,这里没有 extern_var 的补全提示 */
int extern_var = 7431;

屏幕截图(288) 如上图,全局作用域中的 static 后的类型输入没有补全提示

屏幕截图(289) 如上图,全局作用域中的 预处理条件指令 #if 后的宏名没有补全提示

屏幕截图(291) 如上图,函数作用域中的 预处理条件指令 #if 后的宏名有补全提示

下面是对应的测试代码:

如果在全局作用域中使用 static,extern,constexpr,consteval,constinit,预处理条件指令,那么后续的类型输入没有补全提示.zip