I'm using cl.exe v19.12.
To summarize:
SQLite 3.24 compiles fine with warning as error enabled with cl.exe v19.12
SQLite 3.27.1 does not compile with warning as error enabled with cl.exe
v19.12.
To me, it looks like a simple fix to avoid writing "return <expr>" in void
functions even if <expr> is a void function. It just looks broken and
obviously some compilers does not handle this correctly.
FWIW, cl.exe v19.12 does not complain about your example code
(return-coid.cpp)
If you convert your program to C:
#include <stdio.h>
void fa(int i)
{
if (i == 2)
return;
printf("%d\n", i);
} // implied return;
int fb(int i)
{
if (i > 4)
return 4;
printf("%d\n", i);
return 2;
}
typedef struct {
const char* p;
int x;
} pair;
pair fc(const char* p, int x)
{
pair r;
r.p = p;
r.x = x;
return r;
}
void fd()
{
return fa(10); // fa(10) is a void expression
}
int main()
{
fa(2); // returns, does nothing when i==2
fa(1); // prints its argument, then returns
int i = fb(5); // returns 4
i = fb(i); // prints its argument, returns 2
printf("%d\n", i);
printf("%d\n", fc("Hello", 7).x);
fd();
}
The compiler complains:
Z:\retvoid>cl /EHsc /W4 return-void.c
Microsoft (R) C/C++ Optimizing Compiler Version 19.12.25831 for x86
Copyright (C) Microsoft Corporation. All rights reserved.
return-void.c
return-void.c(33): warning C4098: 'fd': 'void' function returning a value
Microsoft (R) Incremental Linker Version 14.12.25831.0
Copyright (C) Microsoft Corporation. All rights reserved.
/out:return-void.exe
return-void.obj
/Jonas
On Mon, Feb 11, 2019 at 11:58 AM Dominique Devienne <[email protected]>
wrote:
> On Mon, Feb 11, 2019 at 11:31 AM Jonas Bülow <[email protected]>
> wrote:
>
> > Sorry, I missed some information. It is the MSVC v15.5 compiler that
> > complains:
> >
> > sqlite3.c(58167): error C2220: warning treated as error - no 'object'
> file
> > generated [c:\work\sqlite-amalgamation-3270100\sqlite3.vcxproj]
> > sqlite3.c(58167): warning C4098: 'sqlite3PagerSnapshotUnlock': 'void'
> > function returning a value
> > [c:\work\sqlite-amalgamation-3270100\sqlite3.vcxproj]
> > Done Building Project "c:\sqlite-amalgamation-3270100\sqlite3.vcxproj"
> > (default targets) -- FAILED.
> >
>
> Buggy compiler? Using VS2017 (cl.exe 19.10) there are no warnings with the
> CppReference code example.
> But again, might depend on sqlite3WalSnapshotUnlock() being void or not.
> --DD
>
> PS: /Wall spews tons of warnings, in MS's own std lib headers...
>
> d:\my\demo>cl /nologo /EHsc /W1 return-void.cpp
> return-void.cpp
>
> d:\my\demo>cl /nologo /EHsc /W2 return-void.cpp
> return-void.cpp
>
> d:\my\demo>cl /nologo /EHsc /W3 return-void.cpp
> return-void.cpp
>
> d:\my\demo>cl /nologo /EHsc /W4 return-void.cpp
> return-void.cpp
>
> d:\my\demo>type return-void.cpp
> #include <iostream>
> #include <string>
> #include <utility>
>
> void fa(int i)
> {
> if (i == 2)
> return;
> std::cout << i << '\n';
> } // implied return;
>
> int fb(int i)
> {
> if (i > 4)
> return 4;
> std::cout << i << '\n';
> return 2;
> }
>
> std::pair<std::string, int> fc(const char* p, int x)
> {
> return {p, x};
> }
>
> void fd()
> {
> return fa(10); // fa(10) is a void expression
> }
>
> int main()
> {
> fa(2); // returns, does nothing when i==2
> fa(1); // prints its argument, then returns
> int i = fb(5); // returns 4
> i = fb(i); // prints its argument, returns 2
> std::cout << i << '\n'
> << fc("Hello", 7).second << '\n';
> fd();
> }
>
> d:\my\demo>return-void.exe
> 1
> 4
> 2
> 7
> 10
>
> d:\my\demo>cl /EHsc /W4 return-void.cpp
> Microsoft (R) C/C++ Optimizing Compiler Version 19.10.25019 for x64
> Copyright (C) Microsoft Corporation. All rights reserved.
>
> return-void.cpp
> Microsoft (R) Incremental Linker Version 14.10.25019.0
> Copyright (C) Microsoft Corporation. All rights reserved.
>
> /out:return-void.exe
> return-void.obj
>
> d:\my\demo>
> _______________________________________________
> sqlite-users mailing list
> [email protected]
> http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
>
_______________________________________________
sqlite-users mailing list
[email protected]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users