vscode-cpptools icon indicating copy to clipboard operation
vscode-cpptools copied to clipboard

"Function definition for '' not found" message appears when defining a function with a macro

Open dortamiguel opened this issue 2 years ago • 8 comments

Environment

  • OS and Version: Ventura 13.6
  • VS Code Version: 1.82.2
  • C/C++ Extension Version: v1.17.5

Bug Summary and Steps to Reproduce

Bug Summary:

If I define a function with a macro vscode can't find the definition and it reports an error

Steps to reproduce: Type this code

#define define_foo(Type) \
    void foo(const string &key, Type value) {}

define_foo(bool);
define_foo(char);

Expected behavior: I don't get this error message image

Other Extensions

No response

Additional context

No response

dortamiguel avatar Sep 25 '23 02:09 dortamiguel

That error appears to be from another extension. Errors from our extension look like C/C++(<error code>). Your message shows no error code and doesn't match any error message we return.

sean-mcmanus avatar Sep 25 '23 17:09 sean-mcmanus

@sean-mcmanus I only have the c++ extension installed

image

and if I disable it the message goes away, also this won't appear as an error. just three dots at the beginning of the string like in the screenshot

dortamiguel avatar Sep 27 '23 03:09 dortamiguel

I reproduce the issue. This is a bug.

bobbrow avatar Sep 27 '23 17:09 bobbrow

Ah, okay, I see now -- it's not an IntelliSense error (red squiggle) it's a CDD error message (from the "...").

sean-mcmanus avatar Sep 28 '23 23:09 sean-mcmanus

The issue is inherited from the shared code from Visual Studio: image

sean-mcmanus avatar Sep 28 '23 23:09 sean-mcmanus

I've encountered this issue with class member functions. If you wrap the class part in a macro, it will think almost every function definition in the class doesn't exist, even if it does.

Example

Foo.hpp

#pragma once

#define CLASS(T) class T

CLASS(Foo)
{
public:
	void Bar();
	void Baz();
	void Test();
};

Foo.cpp

#include "Foo.hpp"

void Foo::Bar()
{
}

void Foo::Baz()
{
}

void Foo::Test()
{
}

Result

image image

Oddly, it appears the first function in the class (Bar) doesn't have the issue, but the ones after it do (Baz and Test).

J0shhT avatar Nov 28 '23 03:11 J0shhT

I'm observing the same, also very visible in Zephyr and it's macros for callback functions:

image

lmapii avatar Jul 20 '24 08:07 lmapii

This problem has been tortured me in the last two weeks, Any update?

zhang-wenchao avatar Oct 15 '24 13:10 zhang-wenchao

Could be possible to just turn off this?

dortamiguel avatar Jan 20 '25 03:01 dortamiguel

Ah, okay, I see now -- it's not an IntelliSense error (red squiggle) it's a CDD error message (from the "...").

What is a "CDD error" and how do I turn it off?

lesiw avatar Aug 07 '25 12:08 lesiw

Sorry for not following up on this issue -- it is actually not a bug, but "by design" -- the feature requires that you create a cpp.hint file with the macro, e.g. #define define_foo(Type). Then the error will disappear.

See https://developercommunity.visualstudio.com/t/C-Create-Definition-suggestions-dont/10826411 .

Also, there is no setting to turn it off, but someone could open a request for us to add such a setting (it might also be possible to submit a PR to enable disabling it from the open source TypeScript).

sean-mcmanus avatar Aug 07 '25 13:08 sean-mcmanus

Sorry for not following up on this issue -- it is actually not a bug, but "by design" -- the feature requires that you create a cpp.hint file with the macro, e.g. #define define_foo(Type). Then the error will disappear.

See https://developercommunity.visualstudio.com/t/C-Create-Definition-suggestions-dont/10826411 .

Also, there is no setting to turn it off, but someone could open a request for us to add such a setting (it might also be possible to submit a PR to enable disabling it from the open source TypeScript).

Creating a cpp.hint file, no matter where, did not solve the problem for me. Either it is not being picked up correctly by the extension, or there's something else going wrong:

Image

I placed a cpp.hint into the workspace root but also in some subfolders:

Image

lmapii avatar Aug 07 '25 14:08 lmapii

@lmapii Your screenshot shows a different error identifier __FILE_NAME__ is undefined. It's already being tracked by https://github.com/microsoft/vscode-cpptools/issues/11164 .

sean-mcmanus avatar Aug 07 '25 14:08 sean-mcmanus