Skip to content

Gets unused variable from generated model file and deprecated function error. #2514

@bgrhnzcn

Description

@bgrhnzcn

I am using Fedora Linux 43 (Workstation Edition).

I see there is a fix for unused variable error but I am getting one right now.

Installed all dependencies from dnf and compiled framework today on my machine, but it keeps creating files with unused variable and deprecated function. I am using postgresql database and this is sql file for table creation:

DROP TABLE IF EXISTS users;

CREATE TABLE IF NOT EXISTS users (
    id SERIAL PRIMARY KEY,
    name VARCHAR(100) NOT NULL,
    surname VARCHAR(100) NOT NULL,
	date_of_birth DATE NOT NULL,
    phone VARCHAR(20) NOT NULL
);

This is the compilation command:

c++ -c -Wall -Werror -Wextra -std=c++20 -MMD -MP -I/usr/include/jsoncpp/ -Isrc/controllers/ -Isrc/entities/ -Isrc/ -Imodels models/Users.cc -o build/obj/models/Users.o

models/Users.cc: In member function ‘void drogon_model::cpp::Users::updateId(uint64_t)’:                                                                                                      
models/Users.cc:420:37: error: unused parameter ‘id’ [-Werror=unused-parameter]                                                                                                               
  420 | void Users::updateId(const uint64_t id)                                                                                                                                               
      |                      ~~~~~~~~~~~~~~~^~                                                                                                                                                
models/Users.cc: In static member function ‘static bool drogon_model::cpp::Users::validJsonOfField(size_t, const std::string&, const Json::Value&, std::string&, bool)’:                      
models/Users.cc:955:41: error: ‘template<class _Codecvt, class _Elem, class _Wide_alloc, class _Byte_alloc> class std::__cxx11::wstring_convert’ is deprecated [-Werror=deprecated-declaration
s]                                                                                                                                                                                            
  955 |             if(pJson.isString() && std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>, wchar_t>{}                                                                                  
      |                                         ^~~~~~~~~~~~~~~                                                                                                                               
In file included from /usr/include/c++/15/locale:47,                                                                                                                                          
                 from /usr/include/c++/15/iomanip:53,                                                                                                                                         
                 from /usr/include/c++/15/bits/chrono_io.h:40,                                                                                                                                
                 from /usr/include/c++/15/chrono:3378,                                                                                                                                        
                 from /usr/local/include/trantor/net/EventLoop.h:29,                                                                                                                          
                 from /usr/local/include/drogon/utils/coroutine.h:17,                                                                                                                         
                 from /usr/local/include/drogon/orm/DbClient.h:33,                                                                                                                            
                 from /usr/local/include/drogon/orm/BaseBuilder.h:18,                                                                                                                         
                 from /usr/local/include/drogon/orm/Mapper.h:17,                                                                                                                              
                 from models/Users.h:13,                                                                                                                                                      
                 from models/Users.cc:8:                                                                                                                                                      
/usr/include/c++/15/bits/locale_conv.h:262:33: note: declared here                                                                                                                            
  262 |     class _GLIBCXX17_DEPRECATED wstring_convert                                                                                                                                       
      |                                 ^~~~~~~~~~~~~~~                                                                                                                                       
models/Users.cc:975:41: error: ‘template<class _Codecvt, class _Elem, class _Wide_alloc, class _Byte_alloc> class std::__cxx11::wstring_convert’ is deprecated [-Werror=deprecated-declaration
s]                                                                                                                                                                                            
  975 |             if(pJson.isString() && std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>, wchar_t>{}                                                                                  
      |                                         ^~~~~~~~~~~~~~~                                                                                                                               
/usr/include/c++/15/bits/locale_conv.h:262:33: note: declared here                                                                                                                            
  262 |     class _GLIBCXX17_DEPRECATED wstring_convert                                                                                                                                       
      |                                 ^~~~~~~~~~~~~~~                                                                                                                                       
models/Users.cc:1007:41: error: ‘template<class _Codecvt, class _Elem, class _Wide_alloc, class _Byte_alloc> class std::__cxx11::wstring_convert’ is deprecated [-Werror=deprecated-declaratio
ns]                                                                                                                                                                                           
 1007 |             if(pJson.isString() && std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>, wchar_t>{}                                                                                  
      |                                         ^~~~~~~~~~~~~~~                                                                                                                               
/usr/include/c++/15/bits/locale_conv.h:262:33: note: declared here                                                                                                                            
  262 |     class _GLIBCXX17_DEPRECATED wstring_convert                                                                                                                                       
      |                                 ^~~~~~~~~~~~~~~                                                                                                                                       
cc1plus: all warnings being treated as errors                                                                                                                                                 
make: *** [Makefile:55: build/obj/models/Users.o] Error 1                                                                                                                                     
                                                                                                                                                                                              
(6 of 29): error: unused parameter ‘id’ [-Werror=unused-parameter]

This is the deprecated errors function:

bool Users::validJsonOfField(size_t index,
                             const std::string &fieldName,
                             const Json::Value &pJson,
                             std::string &err,
                             bool isForCreation)
{
    switch(index)
    {
        case 0:
            if(pJson.isNull())
            {
                err="The " + fieldName + " column cannot be null";
                return false;
            }
            if(isForCreation)
            {
                err="The automatic primary key cannot be set";
                return false;
            }
            if(!pJson.isInt())
            {
                err="Type error in the "+fieldName+" field";
                return false;
            }
            break;
        case 1:
            if(pJson.isNull())
            {
                err="The " + fieldName + " column cannot be null";
                return false;
            }
            if(!pJson.isString())
            {
                err="Type error in the "+fieldName+" field";
                return false;
            }
            if(pJson.isString() && std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>, wchar_t>{}
                .from_bytes(pJson.asCString()).size() > 100)
            {
                err="String length exceeds limit for the " +
                    fieldName +
                    " field (the maximum value is 100)";
                return false;
            }
            break;
        case 2:
            if(pJson.isNull())
            {
                err="The " + fieldName + " column cannot be null";
                return false;
            }
            if(!pJson.isString())
            {
                err="Type error in the "+fieldName+" field";
                return false;
            }
            if(pJson.isString() && std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>, wchar_t>{}
                .from_bytes(pJson.asCString()).size() > 100)
            {
                err="String length exceeds limit for the " +
                    fieldName +
                    " field (the maximum value is 100)";
                return false;
            }
            break;
        case 3:
            if(pJson.isNull())
            {
                err="The " + fieldName + " column cannot be null";
                return false;
            }
            if(!pJson.isString())
            {
                err="Type error in the "+fieldName+" field";
                return false;
            }
            break;
        case 4:
            if(pJson.isNull())
            {
                err="The " + fieldName + " column cannot be null";
                return false;
            }
            if(!pJson.isString())
            {
                err="Type error in the "+fieldName+" field";
                return false;
            }
            if(pJson.isString() && std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>, wchar_t>{}
                .from_bytes(pJson.asCString()).size() > 20)
            {
                err="String length exceeds limit for the " +
                    fieldName +
                    " field (the maximum value is 20)";
                return false;
            }
            break;
        default:
            err="Internal error in the server";
            return false;
    }
    return true;
}

This is the unused variable errrors one:

void Users::updateId(const uint64_t id)
{
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions