0

I use #warning to mark some unfinished functions, so that when someone compiles the code later, they see a hint that they still need to continue to implement. for example:

class HttpDownloadJobAndroid : public HttpDownloadJob
{
public:
    virtual void Download() override
    {
        #warning "Please complete the implementation of the function : HttpDownloadJobAndroid::Download"

        Finished = true;
        Success = false;
    }
};

This works great, but there is a small problem that every time I copy and paste this warning into a new function, I always need to change the function name in it. This will undoubtedly affect some work efficiency. So I thought, is it possible to pack a C++ macro like __FUNCTION__ into this string so I can copy this warning anywhere.

#define _ME_PP_TEXT(Expr) #Expr
#define ME_PP_TEXT(Expr) _ME_PP_TEXT(Expr)
// not work
#warning "Please complete the implementation of the function : " __FUNCTION__
// not work too...
#warning "Please complete the implementation of the function : " ME_PP_TEXT(__FUNCTION__)

I've tried this method, but it doesn't seem to work.
Of course, if there are other better solutions, please teach me, thank you. my compiler is Clang 5.0, target platform is android.

boo
  • 493
  • 6
  • 17
  • 2
    Is it not enough to have the filename and line number in the warning to identify which function it is? – mch Nov 11 '22 at 09:24
  • Does this answer your question? [Does there exist a static\_warning?](https://stackoverflow.com/questions/8936063/does-there-exist-a-static-warning) – VLL Nov 11 '22 at 09:28
  • Preprocessing directives do not know about functions. – n. m. could be an AI Nov 11 '22 at 09:28
  • I would go about this in a totally different way. I would make unit tests for all the functions of HttpDownloadJobAndroid (probably through an abstract base class/interface HttpDownloadJobItf). And then have unit tests failing for those functions that not have been implemented (correctly) yet. That way you also avoid "littering" your production code with debug/todo/logging statements. And you will have regression tests too. – Pepijn Kramer Nov 11 '22 at 09:56
  • You need to tell us what compiler/build-system you are using, because `#warning` is not a standard pre-processor directive. – Adrian Mole Nov 11 '22 at 10:51

0 Answers0