Cleanup: Correcting default cases in node.cc #107339

Merged
Hans Goudey merged 10 commits from mod_moder/blender:tmp_cleanup_ensure_default_cases into main 2023-06-06 19:19:59 +02:00

Add all other enum items to switch statments
instead of using default (added in #107097 to avoid compiler warnings).

Add all other enum items to switch statments instead of using default (added in https://projects.blender.org/blender/blender/pulls/107097 to avoid compiler warnings).
Iliya Katushenock added 1 commit 2023-04-25 16:31:30 +02:00
Iliya Katushenock requested review from Hans Goudey 2023-04-25 16:31:34 +02:00
Iliya Katushenock added this to the Nodes & Physics project 2023-04-25 16:31:38 +02:00
Member

Thanks for the PR, but typically we don't do this, since it prevents warnings for missing cases when adding new values to the enum.

Thanks for the PR, but typically we don't do this, since it prevents warnings for missing cases when adding new values to the enum.
Hans Goudey closed this pull request 2023-04-25 16:32:23 +02:00
Author
Member

@HooglyBoogly I mean I already did it in #107097
Here I do it for defined int keys (doesn't seem to have warnings for them?)
Also, then can I replace the default with other keys in enum switches?

@HooglyBoogly I mean I already did it in https://projects.blender.org/blender/blender/pulls/107097 Here I do it for defined int keys (doesn't seem to have warnings for them?) Also, then can I replace the default with other keys in enum switches?
Member

Hmm, that was not mentioned in the PR description. The best thing to do in that case is to pass around the enum type in the first place, or cast the int to the enum type just for the switch.

Hmm, that was not mentioned in the PR description. The best thing to do in that case is to pass around the enum type in the first place, or cast the int to the enum type just for the switch.
Author
Member

This was a related change. The value is stored using an int, so for the switch I converted it to an enum type.
It wasn't mentioned because I just bypassed the compiler warnings, sorry for not giving it that much importance.

This was a related change. The value is stored using an int, so for the switch I converted it to an enum type. It wasn't mentioned because I just bypassed the compiler warnings, sorry for not giving it that much importance.
Iliya Katushenock added 3 commits 2023-04-25 17:19:43 +02:00
Iliya Katushenock reopened this pull request 2023-04-25 17:32:44 +02:00
Iliya Katushenock added 1 commit 2023-04-25 17:39:56 +02:00
Iliya Katushenock added 2 commits 2023-05-09 13:06:05 +02:00
Hans Goudey requested changes 2023-06-05 23:31:38 +02:00
@ -246,6 +246,8 @@ static void ntree_free_data(ID *id)
ntreeTexEndExecTree(ntree->runtime->execdata);
ntree->runtime->execdata = nullptr;
break;
default:
Member

I don't see a need for this default case, it doesn't make a functional difference or help with warnings.

I don't see a need for this `default` case, it doesn't make a functional difference or help with warnings.
Author
Member

My main motivation is to avoid unsafe behavior. We can't have compiler warnings for this enum items right now, since they're not enums. Likewise below. These are int identifiers. When this is replaced with enums, all elements can be added. But for now, maybe we should just say that the rest are not supported with using default?

My main motivation is to avoid unsafe behavior. We can't have compiler warnings for this enum items right now, since they're not enums. Likewise below. These are int identifiers. When this is replaced with enums, all elements can be added. But for now, maybe we should just say that the rest are not supported with using `default`?
Member

This default case doesn't make things safer, it doesn't change the behavior in this function. The switch case already says "any other value, don't do anything" on its own.

This default case doesn't make things safer, it doesn't change the behavior in this function. The switch case already says "any other value, don't do anything" on its own.
Author
Member

Ah, well, okay, now only a code style guide on my side/

Ah, well, okay, now only a code style guide on my side/
mod_moder marked this conversation as resolved
@ -4166,6 +4171,8 @@ void node_type_base(bNodeType *ntype, const int type, const char *name, const sh
switch (type) {
#include "NOD_static_types.h"
default:
Member

Same here

Same here
mod_moder marked this conversation as resolved
@ -4291,6 +4298,8 @@ void node_type_size_preset(bNodeType *ntype, const eNodeSizePreset size)
case NODE_SIZE_LARGE:
node_type_size(ntype, 240, 140, NODE_DEFAULT_MAX_WIDTH);
break;
default:
Member

And here I think

And here I think
mod_moder marked this conversation as resolved
Iliya Katushenock added 3 commits 2023-06-06 18:58:06 +02:00
Iliya Katushenock changed title from Cleanup: Ensure default cases in node.cc to Cleanup: Correcting default cases in node.cc 2023-06-06 18:59:32 +02:00
Iliya Katushenock requested review from Hans Goudey 2023-06-06 19:01:02 +02:00
Hans Goudey approved these changes 2023-06-06 19:19:26 +02:00
Hans Goudey merged commit 8dc70b9e2e into main 2023-06-06 19:19:59 +02:00
Iliya Katushenock deleted branch tmp_cleanup_ensure_default_cases 2023-06-06 19:24:01 +02:00
Sign in to join this conversation.
No reviewers
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#107339
No description provided.